Refactored and moved some of the smaller functions
All tests passed