tests pass with rewritten function