Fix to ndim. Seems to work now.