Reworked the http connection and errors handling code to be more resiliant (and removed some bugs). Fixed up some copy and paste documentation errors.
Note that this version needs some testing. It should be more resialiant than the old version, which in some respects had slightly wrong error handling (I was cutting corners a bit).