Finally fixed write_string so it compiles now
Added heartbeat thread