                     "keyGap%dx%d",
                     row: i,
                     startIndex: 1,
-                    endIndex: keyboard.rows[i].count - 1,
+                    endIndex: rowsCount - 1,
                     vertical: false,
                     width: layout["keyGap"]!)
             }

                    "keyGap%dx%d",
                    row: i,
                    startIndex: 2,
                    endIndex: keyboard.rows[i].count - 2,
                    vertical: false,
                    width: layout["keyGap"]!)
            }

            // TODO: both of these should be determined based on the model data, not the row #
            let isSideButtonRow = (i == 2)
            let isEquallySpacedRow = (i == 3)
            let rowsCount = keyboard.rows[i].count
            
            if isSideButtonRow {
                addGapPair(
                    "keyGap%dx%d",
                    row: i,
                    startIndex: 0,
                    endIndex: rowsCount,
                    leftAnchor: "leftSpacer",
                    rightAnchor: "rightSpacer",
                    vertical: false,
