Refactored some code.
Started to add tests.