Clean up and properly implement opening and closing link search