better code for frequency
added containsWithFrequency