 
 // MARK: - ImageTaggerViewController: UIViewController, Alertable
 
-class ImageTaggerViewController: UIViewController, Alertable {
-    
-    // MARK: - Properties
-    
+final class ImageTaggerViewController: UIViewController, Alertable {
+    
+    // MARK: - Instance Variables
+
+    /// Image for analysis and discovery.
+    /// Hashtags will be generated using this image.
     var taggingImage: UIImage!
+
     var persistenceCentral: PersistenceCentral!
     
     private let imaggaApiClient = ImaggaApiClient.shared
-    
-    fileprivate var generatedTags: [ImaggaTag]?
-    fileprivate var createdCategory: Category?
-    fileprivate lazy var temporaryContext: NSManagedObjectContext = {
+
+    /// Generated hashtags from the `taggingImage`.
+    private var generatedTags: [ImaggaTag]?
+
+    /// Category associated with the `generatedTags`.
+    private var createdCategory: Category?
+
+    private lazy var temporaryContext: NSManagedObjectContext = {
         let context = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
         context.persistentStoreCoordinator = self.persistenceCentral.coreDataStackManager.persistentStoreCoordinator
+
         return context
     }()
     
-    // MARK: Outlets
-    
-    @IBOutlet var cancelBarButtonItem: UIBarButtonItem!
+    // MARK: IBOutlets
+
     @IBOutlet var imageView: UIImageView!
     @IBOutlet var activityIndicator: UIActivityIndicatorView!
+    @IBOutlet var cancelBarButtonItem: UIBarButtonItem!
     @IBOutlet var generateBarButtonItem: UIBarButtonItem!
     @IBOutlet var resultsBarButtonItem: UIBarButtonItem!
     @IBOutlet var saveResultsBarButtonItem: UIBarButtonItem!
     
-    // MARK: - View Life Cycle
+    // MARK: - UIViewController lifecycle
     
     override func viewDidLoad() {
         super.viewDidLoad()

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

        configureUI()
    }
    
}

// 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?.handleGeneratedTags(tags)
        }) { [weak self] error in
            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 {
