fixed the race conditios while saving data.