PS. I realize you present even better solution; still, first version seems like a thing nice enough to have in a toolbox