Fixed a bug with custom hostname

also added integration test