made some improvements to get_first_link