Updated reduce script