Move some stuff from tables.c