Changes to countOccurrences, started calculating distanceMatrix