Move hostname detection logic to allow replacement
Fix build