Minor improvements to the keepalive mechanism