changed flattenJoin implementation.