The code seems to assume 3D arrays.