Updated error checking.