Combined the two event handlers into one