Added check for err code