Would you like to apply this to 57-58 and replace the ndim == 3 magic, your approach is better here!