Adding logging to debug error handler issue. Also reorder eventemitter listening to put the error handler on first