handleAddWord' :: String -> Deck -> Kerchief ()
handleAddWord' word deck = io (lookupWord word) >>= selectEntry
  where
    selectEntry :: [Entry] -> Kerchief ()
    selectEntry [] = putStrLn "No definition found."
    selectEntry es = do
        printNumberedWith (\(Entry word def mpos phonetic _) -> 
            word ++ " " ++ phonetic ++ maybe " " (\pos -> " (" ++ pos ++ ") ") mpos ++ def) es
        putStrLn "Which definition? (\"-\" to go back)"
        getLine >>= \ms -> case ms of
            "-" -> putStrLn "No card added."
            s   -> maybe badInput selectEntry' (reads' s)
      where
        selectEntry' :: Int -> Kerchief ()
        selectEntry' n
            | n < 1 || n > length es = badInput
            | otherwise = doAddCard (entryToFront entry) (entryDefinition entry) (entrySoundUrl entry) deck
          where
            entry :: Entry
            entry = es !! (n-1)

        badInput :: Kerchief ()
        badInput = putStrLn "Please pick a valid integer."
handleAddWord' :: String -> Deck -> Kerchief ()
handleAddWord' word deck = io (lookupWord word) >>= selectEntry
  where
    selectEntry :: [Entry] -> Kerchief ()
    selectEntry [] = putStrLn "No definition found."
    selectEntry es = do
        printNumberedWith (\(Entry word def mpos phonetic _) -> 
            word ++ " " ++ phonetic ++ maybe " " (\pos -> " (" ++ pos ++ ") ") mpos ++ def) es
        putStrLn "Which definition? (\"-\" to go back)"
        getLine >>= \ms -> case ms of
            "-" -> putStrLn "No card added."
            s   -> maybe badInput selectEntry' (reads' s)
      where
        selectEntry' :: Int -> Kerchief ()
        selectEntry' n
            | n < 1 || n > length es = badInput
            | otherwise = doAddCard (entryToFront entry) (entryDefinition entry) (entrySoundUrl entry) deck
          where
            entry :: Entry
            entry = es !! (n-1)

        badInput :: Kerchief ()
        badInput = putStrLn "Please pick a valid integer."
handleAddWord' word deck = io (lookupWord word) >>= selectEntry
  where
    selectEntry :: [Entry] -> Kerchief ()
    selectEntry [] = putStrLn "No definition found."
    selectEntry es = do
        printNumberedWith (\(Entry word def mpos phonetic _) -> 
            word ++ " " ++ phonetic ++ maybe " " (\pos -> " (" ++ pos ++ ") ") mpos ++ def) es
        putStrLn "Which definition? (\"-\" to go back)"
        getLine >>= \ms -> case ms of
            "-" -> putStrLn "No card added."
            s   -> maybe badInput selectEntry' (reads' s)
      where
        selectEntry' :: Int -> Kerchief ()
        selectEntry' n
            | n < 1 || n > length es = badInput
            | otherwise = doAddCard (entryToFront entry) (entryDefinition entry) (entrySoundUrl entry) deck
          where
            entry :: Entry
            entry = es !! (n-1)

        badInput :: Kerchief ()
        badInput = putStrLn "Please pick a valid integer."