Added test suite and cleaned up code