Fixed server getting stuck in an endless loop and not terminating