Fix various issues where changing the expression could lead to changed behaviour.