         
         for i in 0..keyboard.count {
             for j in 0..keyboard[i].count {
-                let keyName = "key\(i)x\(j)"
+                let keyName = "key\(j)x\(i)"
                 let key = self.elements[keyName]
                 
-                allConstraints += "[keyGap\(i)x\(j)][\(keyName)(keyWidth)]"
+                allConstraints += "[keyGap\(j)x\(i)][\(keyName)(keyWidth)]"
                 allConstraints += "V:[rowGap\(i)][\(keyName)(keyHeight)]"
             }
         }

    
    func addEdgeConstraints() {
        let spacers = [
            "leftSpacer": Spacer(),
            "rightSpacer": Spacer(),
            "topSpacer": Spacer(),
            "bottomSpacer": Spacer()]
        
        // basic setup
        for (name, spacer) in spacers {
            spacer.setTranslatesAutoresizingMaskIntoConstraints(false)
            spacer.layer.backgroundColor = UIColor.redColor().CGColor
            self.elements[name] = spacer
            self.view.addSubview(spacer)
        }

                    allConstraints += "[leftSpacer][\(keyGapName)]"
                }
                else if isRightMarginGap {
                    allConstraints += "[key\(j-1)x\(i)][\(keyGapName)(\(canonicalMarginGap))][rightSpacer]"
                }
                else {
                    allConstraints += "[key\(j-1)x\(i)][\(keyGapName)(keyGap)]"
                }
                
                // each gap has the same height
