WIP: Some more fixes & improvements to rewriteExpression