Refactor parse_reference