Updated reduction code