refactoring ctx_links