replace match and assignments with a nested match