Added checking for invalid commands before running the list of commands in perform_commands.