refactoring tests and code