better solution for wordOccurrences