refactor tag processing code in iterlinks()