Would it be worth refactoring the names of tables and fields out as constants on top of the file? That may make it easier to read/reason about the code.