You should always unset global variables such as %link there.. That lets you not repeat the code at the top, too, with another method.