Fix hostname changing.

Fixes #1160
Fixes #1132