extract same update functionality into a function