refactoring and removing unused code
adding test coverage