Refactor of computeW function.