Minor re-factoring, all tests pass