def organize_commands(corrected_commands):
    try:
        first_command = next(corrected_commands)
        yield first_command
    except StopIteration:
        return
    without_duplicates = {
        command for command in sorted(
            corrected_commands, key=lambda command: command.priority)
        if command != first_command}
    sorted_commands = sorted(
        without_duplicates,
        key=lambda corrected_command: corrected_command.priority)
    logs.debug('Corrected commands: '.format(
        ', '.join(u'{}'.format(cmd) for cmd in [first_command] + sorted_commands)))
    for command in sorted_commands:
        yield command