Logging and attempt to fix connection problems (this involves horrible hackery)