Fix handshake and heartbeat timer logic