More robust error checking.