improvements to save data correctly on reconnections