Made more robust against against sleeping clients and client disconnects