adding lock/unlock functionality to event handler to prevent changes while iterating