Modified to allow different handling code for each event.