refreshButtons :: IORef GameState -> IO ()
refreshButtons gameStateRef = do
  gameState <- readIORef gameStateRef
  let (up,down,left,right) = getButtonBoxes gameState
      n = getN gameState
      rotStep = getRotStep gameState
      drawingArea = getDrawingArea gameState
      xml = getXML gameState
  [upB,downB,leftB,rightB] <- mapM (mapM $ (\ k -> fmap ((,) k) $ buttonNewWithLabel $ show k)) $ replicate 4 [3..n]
  containerForeach up (containerRemove up)
  containerForeach down (containerRemove down)
  containerForeach left (containerRemove left)
  containerForeach right (containerRemove right)
  mapM_ (processButton gameStateRef up 1) upB
  mapM_ (processButton gameStateRef down 3) downB
  mapM_ (processButton gameStateRef left 2) leftB
  mapM_ (processButton gameStateRef right 0) rightB
  buttonClickAction xml "rotCW" (buttonAction gameStateRef 4 0)
  buttonClickAction xml "rotCCW" (buttonAction gameStateRef 5 0)
  return ()
refreshButtons :: IORef GameState -> IO ()
refreshButtons gameStateRef = do
  gameState <- readIORef gameStateRef
  let (up,down,left,right) = getButtonBoxes gameState
      n = getN gameState
      rotStep = getRotStep gameState
      drawingArea = getDrawingArea gameState
      xml = getXML gameState
  [upB,downB,leftB,rightB] <- mapM (mapM $ (\ k -> fmap ((,) k) $ buttonNewWithLabel $ show k)) $ replicate 4 [3..n]
  containerForeach up (containerRemove up)
  containerForeach down (containerRemove down)
  containerForeach left (containerRemove left)
  containerForeach right (containerRemove right)
  mapM_ (processButton gameStateRef up 1) upB
  mapM_ (processButton gameStateRef down 3) downB
  mapM_ (processButton gameStateRef left 2) leftB
  mapM_ (processButton gameStateRef right 0) rightB
  buttonClickAction xml "rotCW" (buttonAction gameStateRef 4 0)
  buttonClickAction xml "rotCCW" (buttonAction gameStateRef 5 0)
  return ()
refreshButtons gameStateRef = do
  gameState <- readIORef gameStateRef
  let (up,down,left,right) = getButtonBoxes gameState
      n = getN gameState
      rotStep = getRotStep gameState
      drawingArea = getDrawingArea gameState
      xml = getXML gameState
  [upB,downB,leftB,rightB] <- mapM (mapM $ (\ k -> fmap ((,) k) $ buttonNewWithLabel $ show k)) $ replicate 4 [3..n]
  containerForeach up (containerRemove up)
  containerForeach down (containerRemove down)
  containerForeach left (containerRemove left)
  containerForeach right (containerRemove right)
  mapM_ (processButton gameStateRef up 1) upB
  mapM_ (processButton gameStateRef down 3) downB
  mapM_ (processButton gameStateRef left 2) leftB
  mapM_ (processButton gameStateRef right 0) rightB
  buttonClickAction xml "rotCW" (buttonAction gameStateRef 4 0)
  buttonClickAction xml "rotCCW" (buttonAction gameStateRef 5 0)
  return ()