refactored - all tests pass