Rewrites and optimizes a lot.