Merge "Move optimization to later part of pipeline" into tm-dev