Fix issues with pending clients and main loop