Now uses function variables instead of direct table names