Fix expand tree algorythm