Updated event handler to correct exit proc