modified event handler to be dynamic