Event handling code improved.