move placement of error checking