Refactor some code out of the unit tests to decouple functionality from implementation