Fix and carefully test the contains function