more unit tests and couple of bug fixes