Update to add counting distinct words, logic fixes