first working version of reording 3D arrays