fix error checking bug