changed TH logic to account for nested tables