         configureUI()
     }
     
-    // MARK: - Actions
-    
+}
+
+// MARK: - ImageTaggerViewController (Data) -
+
+extension ImageTaggerViewController {
+
+    private func handleGeneratedTags(_ tags: [ImaggaTag]) {
+        generatedTags = tags
+        setUIState(.doneWithNetworking)
+
+        let alert = UIAlertController(title: "Success",
+                                      message: "Tags successfully generated. Do you want save or see them?",
+                                      preferredStyle: .alert)
+        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
+        alert.addAction(UIAlertAction(title: "Save", style: .default) { [weak self]  _ in
+            guard let strongSelf = self else { return }
+            strongSelf.saveResults(strongSelf)
+        })
+        alert.addAction(UIAlertAction(title: "See Results", style: .default) { [weak self]  _ in
+            guard let strongSelf = self else { return }
+            strongSelf.showResults(strongSelf)
+        })
+
+        present(alert, animated: true, completion: nil)
+    }
+
+    private func createCategory(with name: String) {
+        let name = name.trimmingCharacters(in: .whitespaces)
+        let manager = persistenceCentral.coreDataStackManager
+        let context = manager.managedObjectContext
+
+        let category = Category(name: name, context: context)
+        ImaggaTag.map(on: generatedTags!, with: category, in: context)
+        manager.saveContext()
+
+        createdCategory = category
+
+        saveResultsBarButtonItem.isEnabled = false
+        showResults(self)
+    }
+
+}
+
+// MARK: - ImageTaggerViewController (Actions) -
+
+extension ImageTaggerViewController {
+
     @IBAction func cancelDidPressed(_ sender: AnyObject) {
         dismiss(animated: true, completion: nil)
     }
-    
+
     @IBAction func generateTags(_ sender: AnyObject) {
         setUIState(.networking)
         imaggaApiClient.taggingImage(taggingImage, success: { [weak self] tags in
-            self?.processOnGeneratedTags(tags)
+            self?.handleGeneratedTags(tags)
         }) { [weak self] error in
-            self?.generatedTags = nil
-            self?.setUIState(.doneWithNetworking)
-            let alert = self?.alert("Error", message: error.localizedDescription, handler: nil)
-            self?.present(alert!, animated: true, completion: nil)
-        }
-    }
-    
+            guard let strongSelf = self else {
+                return
+            }
+
+            strongSelf.generatedTags = nil
+            strongSelf.setUIState(.doneWithNetworking)
+
+            let alert = strongSelf.alert("Error", message: error.localizedDescription,
+                                         handler: nil)
+            strongSelf.present(alert, animated: true, completion: nil)
+        }
+    }
+
     @IBAction func showResults(_ sender: AnyObject) {
         let tagListViewController = TagListViewController(persistenceCentral: persistenceCentral)
-        
+
         if let createdCategory = createdCategory {
             tagListViewController.category = createdCategory
         } else {

            UIUtils.hideNetworkActivityIndicator()
            activityIndicator.stopAnimating()
            generateBarButtonItem.isEnabled = true
            updateResultsButtonState()
        }
    }
    
}

            tagListViewController.tags = ImaggaTag.map(on: generatedTags!,
                                                       in: temporaryContext)
        }

        navigationController?.pushViewController(tagListViewController, animated: true)
    }

    @IBAction func saveResults(_ sender: AnyObject) {
        func showAlert() {
            let alert = self.alert(
                "Invalid category name",
                message: "Try again",
                handler: { [weak self] in
                    self?.saveResults($0)
                }
            )

            present(alert, animated: true, completion: nil)
        }

        var categoryNameTextField: UITextField?

        let alert = UIAlertController(title: "Create Category",
                                      message: "To save the tags, please enter the category name.",
                                      preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        alert.addAction(UIAlertAction(title: "Save", style: .default, handler: { [unowned self] _ in
            guard let name = categoryNameTextField?.text, !name.isEmpty else {
                showAlert()
                return
            }

            self.createCategory(with: name)
        }))
        alert.addTextField { textField in
            categoryNameTextField = textField
            categoryNameTextField?.placeholder = "Enter category name"
        }

        present(alert, animated: true, completion: nil)
    }

}

// MARK: - ImageTaggerViewController (UI) -

extension ImageTaggerViewController {
    
    private func configureUI() {
        setUIState(.default)
        navigationController?.view.backgroundColor = .white
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back",
                                                           style: .plain,
                                                           target: nil,
                                                           action: nil)
    }
    
    private func setUIState(_ state: UIState) {
        switch state {
        case .default:
            imageView.image = taggingImage
