Add debug variables, refactor tables.h/c