improved function tableExists