Wrap handlers in an anonymous function