write reduce script