table logic