implement event middleware handling properly