refactor link code