calculate table lengths
rename