refactoring and updating tests