Cleanup, and added separate class for testing. Commit added tests if
possible.