optimization rewrites + fixes