updated event handler function to be generic