Fix more edge cases in #contains().

This should fix issue #346 for good.