Don't assume that a response has any particular structure

This avoids some undef warnings
Move cmd_return check up a little higher to simplify the code