fix bugs found by dave's fuzzing