Moving the event conversion code to a function