Fixed null pointer bug for connection.