Add ndim argument in utility method