Fix delayed firing of event handlers

The mechanism that was supposed to batch handlers during an operation and
fire them afterwards was broken -- handlers triggered during endOperation were
fired immediately.

Should be better now.

Closes #1226