more unit tests and some code fixes