Added write and read of state to file