Add missing error flag initialization and setting