Cleaned event handler code.