Enhanced code for 'last' event