def _reverse_xyz_buffer(buff, output):
    """Reverse the order in a XYZ buffer and extract frames.

    Parameters
    ----------
    buff : string
        A buffer read from a .xyz file.
    output : object like ``file object``
        Where we write the reversed frames.

    Returns
    -------
    out : string
        The left-over data which did not make a full frame.

    """
    frame = []
    finish_next = False
    for lines in reversed(buff.split('\n')):
        if not lines:
            continue
        frame.append(lines)
        if finish_next:
            output.write('\n'.join(frame[::-1]))
            output.write('\n')
            output.flush()
            frame = []
            finish_next = False
            continue
        if lines.find('# Step') != -1:
            finish_next = True
    if not frame:
        return None
    return '\n'.join(frame[::-1])
