Fixing the code and rewriting the tests.