Fix code assuming that the Reg* functions set the last error code