Rewrite nested states