fix several bugs; simplify multi-table query process