Cleanup and added tests.