Moved some of that code from the tests to the actual implementation