Started refactoring.
Refactored tests.