Fixed crash due to modifying key collection while accessing it