Tightened up code, added collections.Counter and smoothed out loops, removed unnecessary function