Do refactoring and clean up