Refactored several methods and fixed some of the unit tests