Refactoring and polish