Removes duplicated code in query_tables_api