updated emit to be error first