clean up the error reporting code according to code review