Cleaned up and added test.