more unit tests, and minor bug fix