             transform = CATransform3DTranslate(transform, point.x, point.y, point.z)
             
             itemView.layer.transform = transform
-            viewPositions[index] = point
+            viewPositions[itemView] = point
         }
     }
     

            }
        }()
        
        for (index, itemView) in itemViews.enumerate() {
            transformView.insertSubview(itemView, atIndex: 0)
            itemView.frame.size = CGSize(width: 300, height: 500) // TODO: change hardcoded values
            
            let panGesture = UIPanGestureRecognizer(target: self, action: #selector(viewWasPanned))
            itemView.addGestureRecognizer(panGesture)
            panGesture.enabled = true
            
             // TODO: remove this? useful for debugging
            itemView.tag = index + 1
            print("tag: \(itemView.tag), view: \(itemView)")
        }
        
        layoutItemViews()
    }
    
    private func shiftItemViews(byOffset offset: CGFloat) {
        // TODO: clean this up
        
        rootOffset += offset
        
        for (index, itemView) in itemViews.enumerate() {
            var transform = CATransform3DIdentity

            // We subtract from the root offset to put cards further behind each other
            let progress = (rootOffset - CGFloat(index * 50)) / 10.0
            
            var point = viewPositions[itemView]!
            // Z grows linearly when progress is past 0
            point.z = progress > 0 ? 3 * progress : 0
            // X grows using an exponential function to ensure that as progress
