Simply had to tell a variable to ‘solve’ for itself before encoding and writing to a file. Now restarts work beautifully!