minor refactoring, tests passing