Refactor the code to be more object oriented to make it a bit easier to test.