Refactored some code into these files.
Refactoring to make testing easier.