                 movie = notificationMovie
             }
             else if let indexPath = self.tableView.indexPathForSelectedRow() {
-                movie = movies[indexPath.row]
+                let entry = movies[indexPath.section]
+                movie = entry.1[indexPath.row]
             }
             let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
             controller.currentMovieName = movie

    // MARK: - Table View

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return movies.count
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell

        let object = movies[indexPath.row]
        cell.textLabel!.text = object
        return cell
    }
    
    override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return "Available disk space: \(diskSpaceAvailable)"
    }
}


import UIKit

// Adapted from
// http://www.raywenderlich.com/82599/swift-functional-programming-tutorial
typealias Entry = (Character, [String])

func buildIndex(words: [String]) -> [Entry] {
    func distinct<T: Equatable>(source: [T]) -> [T] {
        var unique = [T]()
        for item in source {
            if !contains(unique, item) {
                unique.append(item)
            }
        }
        return unique
    }
    
    func firstLetter(str: String) -> Character {
        return Character(str.substringToIndex(advance(str.startIndex, 1)).uppercaseString)
    }

    let letters = words.map { word -> Character in
        firstLetter(word)
    }
    let distinctLetters = distinct(letters)
    
    return distinctLetters.map { letter -> Entry in
        return (letter, words.filter { word -> Bool in
            firstLetter(word) == letter
        })
    }
}


class MasterViewController: UITableViewController {

    var detailViewController: DetailViewController? = nil
    var selectedMovieTitle : String? = nil
    var movies = [Entry]()
    var sections = [String]()
    var diskSpaceAvailable = ""

    override func awakeFromNib() {
