Event handler matching optimization.
Simply tooked from older 1.7.2 version and merged into current