added error checking in invokeCmd()