added unit tests, cleanup, refactoring