Made a slight modification so the application doesn't crash if the connection hasn't been made