only use host_key if it is not None

Really make sure we are not using anything related to `host_keys` unless it is not None.

Moved the logic so that this happens correctly.