Add a "Restart" command and refactor codes