Add more robust error checking.