Refactored classes and added unit tests.