add some tests and fix the bugs that cropped up with the tests