added the code for closing the server when all its connections are dead