optimize ast for environment