Refactoring, clean up and polish