Fix unit tests, make the code more testable.