Small fixes. Generate tree need optimization