Fixed race conditions in event handler

Fixed race conditions in event handler by blocking on acces to state