events handling optimization