Refactor for a better use of table metadata