Fixed code for reduce