Cleanup and added unit test.