Round 1 of refactoring - 1700 lines reduced to 200