fixing error checking