refactoring and cleaning up