Tests, and fixes for the bugs those tests caught.
more tests