Fixed problem with previous hack where the loop terminates upon certain disconnection-related exceptions.