Updated for Py3, fixed a bug that shuffled commands.