* Some changed to avoid ConcurrentModificationExceptions (fixes #333).
* Some minor code optimisations.