Improved code modularity and fixed threads failing to terminate on server connection loss.