Make some of the function more testable