Fix bug causing java.util.ConcurrentModificationException