changed the data structure to a defaultdict to make the code a little more readable