Improved hostname handling