handle deleting from map during iteration correctly (fixes #85)