Cleaning up and refactoring