update saving document logick
refactor of updating documents