Improved constant-folding and other cleanups