Cleaned up and added tests.