Added events. Code is likely broken as it is untested.