added correct handling when client disconnects