added unit tests and fixed issues they found