Fix $link being tested against wrong condition