Cleaning up the code and refactoring.