I think this is the way to do it, I don't see this code living anywhere else at present