improve sortedTable method and tests