Refactor to allow output to be tested