Improved events code
Merge remote-tracking branch 'upstream/master'