fixed possible null pointer exception on connection failures