 //            }
 //            else if reset == "wrap" {
             if (true) {
-                if (x < 1) {
-                    x = nx-1
+                if (pos.x < 1) {
+                    pos.x = nx-1
                 }   
-                else if (x > nx-1)
+                else if (pos.x > nx-1)
                 {   
-                    x = 1
+                    pos.x = 1
                 }
-                if (y < 2)
+                if (pos.y < 2)
                 {
-                    y = ny-1
+                    pos.y = ny-1
                 }
-                else if (y > ny-1)
+                else if (pos.y > ny-1)
                 {
-                    y = 2
+                    pos.y = 2
                 }
             }
             lastPos = UInt(arc4random_uniform(6))
         }
 
-        drawCube(xi: x, yi: y, color: NSColor.greenColor(), skip: skip)
+        drawCube(color: NSColor.greenColor(), skip: skip)
     }
     
-    func drawCube(#xi: Int, yi: Int, color: NSColor, skip: Int)
+    func drawCube(#color: NSColor, skip: Int)
     {
-        let h = sizey
-        let w = sizex
+        let (w, h) = cubeSize()
         let s = h/2
-        
-        let x = xi * w
-        var y = yi * h
-        
-        if (xi%2 == 1)
-        {
-            y -= h/2
-        }
-        
+        let x = pos.x*w
+        let y = (pos.x%2 == 0) ? (pos.y*h) : (pos.y*h - h/2)
+     
         if skip != 0 { // top
             color.set()
             let path = NSBezierPath()

        switch nextPos
        {
        case 0: // up
                y += 1
            
        case 1: // right
                if (x%2)==1 {
                    y -= 1
                }
                x += 1

        case 2: // left
                if (x%2)==1 {
                    y -= 1
                }
                x -= 1

        case 3: // down
                y -= 1
                skip = 0 // dont paint top

        case 4: // back left
                if (x%2)==0 {
                    y += 1
                }
                x -= 1
                skip = 2 // dont paint right

        case 5: // back right
                if (x%2)==0 {
                    y += 1
                }
                x += 1
                skip = 1 // dont paint left
            
            default:
                break
        }

        if (x < 1 || y < 2 || x > nx-1 || y > ny-1) {
//            if reset == "center" {
//                x = cx
//                y = cy

    }
    
    func setup() {
        numrows = min(numrows, Int(bounds.size.height)/2)
    }
    
    override func drawRect(rect: NSRect) {
