a little more robust error checking