Rewriting core LinkHelper to avoid double matching in the middle