Refactoring and more unit testing.