my own version of ndim