It's a minor thing, but this method will return nil if hostname is "".  It might be better to write:

    hostname.downcase! if hostname.present?
    hostname