refactored tests and code