refactor some repeated code
refactor, extract some methods from the formatting code