Shuffle gateway logic around for improved reconnecting.

Fixes #957
Changelog re #957
Merge branch '1.5' into 1.6

Conflicts:
	docs/changelog.rst