refactored code to get title and url