Refactors generate_link()