added writing of time offset and fixed potential segfault