updated sort reduce