Rewritings and optimizations