refactoring and removing unused code