Fix a bug revealed by a deep QuickCheck search

Inserting the keys ["a","b","a"] resulted in a singleton tree (!?).
Fix infinite-loop-at-end-of-input bug and Arbitrary instance

--HG--
extra : amend_source : 5dbbe400f578f46ba0052679d0b25dc20802e7ff