Implemented NDIterator for general purpose (maybe slow)