Adjusted code to resume normal operation after disconnect.