Revised keep-alive and general bug fixes