Small optimizations of event dispaching code