Move event handlers to inside counter function.