Refactoring and cleaning up some code.