Check if the command exists

The lines 13 to 17 are checking if the command exists before executing it, othewise no command will be executed.