[BUGFIX] Fix minor error handler code bugs