group update of W into a function

this includes updateW, updateZ0, updateZ1.