misc functions used to create total_table