add event emitters, clean up code