Fixes bugs around MERGE

* Allows MERGE to run inside FOREACH
* Allows MERGE to handle patterns with no parts already known