Refactoring and more robust unit tests.