refactoring to support supporting with updates
add id's to th for sorting