some error checking with better reporting of the failed condition