refactoring and test fix