Fixed the generation of join clauses