This is done in a couple places. It should be factored out.