Refactoring code. Better tests.