update function

split to smaller function