speed up function 'contains'