Added an init fn and move the event registration code there.