detangling util and test code
passing all tests