Made keepalive simpler for better stability