Changed obj->pair flattening to only rewrite what's used in queries.
Added auto-recognition of relations in the input program.