Refactor parse_file function.