refactoring and fixing error in unit test