Fixed bugs in building afs ast tree