Code Cleanup and Network Status detection code