this logic was hard to read and understand. I think it's better as `hostname_has_port` function. It's possible that this function is more widely useful and should be moved somewhere else.