refactoring and code polishing