Added better error handling when running commands.