Writing keep alive correctly