Restructure code to count word occurences and filter when too few words