fix error checking