refactored links.js code