Deal with the ConcurrentModification issue. Fixes #873