added unit tests and cleaned up some other issues