MOD: pass task state by parameter-passing instead of by mutable variables.