Made some tweaks suggested by Carl, fixed some api exception handling