tbl updated and code restructure