add more tests and fix the bugs they uncovered