Starting to clean up code and add tests.