fixed compatibility issues and added proper handling for disconnecting clients