Moved out the event handler function definition

so that there's only one function created for all the comments