added codes to construct tree for multiple joins