Add op_logic && free many mallocs (segfault when freeing **cmds)