updated fore more than one tables with new algorithm