removed unused code, refactoring and unit tested