Fixed possible data loss from restarts