Refactor retrieve_data to improve style