Converted Event handling code to lambda functions