ConcurrentModificationException solved

To avoid removing items from a list and iterating over it at the same
time, convert the list to a second list. Iterate over the second while
deleting from the first. In this case, all I had to do was create a new
ArrayList from the key sets. This can be done inside the foreach loops,
so no additional lines of code were needed.