Implement #9
Move event handlers to inner scope