refactor, now using event emitters