Refactor parse_term.