Simplified code; added unit test.
Removed unused code.