<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def fix_quotes(cls, query_string):
 """Heuristic attempt to fix unbalanced quotes in query_string."""

        if query_string.count('"') % 2 == 0:
            # no unbalanced quotes to fix
            return query_string

        fields = []  # contains what's matched by the regexp
        # e.g. fields = ['sort:pubDate', 'author:"first last"']

        def f(match):
            fields.append(match.string[match.start():match.end()])
            return ''

        # terms will be all the search terms that don't have a field
        terms = re.sub(r'[^\s:]*:("[^"]*"|[^\s]*)', f, query_string)
        query_string = '{}" {}'.format(terms.strip(), ' '.join(fields))
        return query_string