Made event handler more generic