Change algorithm of building afs ast tree (currently don't fully worked)