added unit tests and some comments