Fix hasOccurence, add corresponding test