Added keep alive and more guard against connection close.