Fix script

some edge cases found with QuickCheck