Made a bunch of fixes to refactored code