add tests, fix a few small errors