Added event middleware line for optionally intercepting events