added caching of links. May need some refactoring later