updated tree-building routine, which now supports transitions