Improved handling of non 2xx return codes

Pass through any non-2xx return codes and leave the output untouched.

Did some minor code cleanup on the way.

----------------------