refactored ndimensonal array