Tidy up event listener code a little