Move repeated code into general formatting