Make keepalive handling more robust, this should now match what OpenSSH does