Fix conflicting variable name. #504

This was obviously screwing up everything.
Improve link merging test case and fix self-links

Refs #504