refactored reducedim