some refactoring for reduce dim