Started refactoring.
Finished first round of refactoring.