Started refactoring and cleaning up