Various fixes and improvements in wreduce pass