Fixing the code crashing when not connected