Finished cleaning and refactoring supplied code