add thread to the save function