It's too bad we had to write all this out. I can imagine that several of our other sites do similar things. Perhaps we should consider, in the back of our minds, how we might factor this out into elasticutils or otherwise make it unnecessary.