generator and optimizations