Updated the code to check the network status