preventing null pointer during connection if hostname is nil