Refactor 'getHref' function