Do more refactoring and clean up