code refactoring and cleaning