refactoring and few unit tests added