Refactor code to have a display event function.