better implementation fo the contains method