Totally refactor the command handling