apply optimizations