added  unit tests/cleaned up some code