     }
 
     override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return movies.count
+        return movieSearcher.hits.count
     }
     
     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
         let cell = tableView.dequeueReusableCellWithIdentifier("movieCell", forIndexPath: indexPath) 
 
         // Load more?
-        if (indexPath.row + 5) >= (movies.count - 1) {
-            loadMore()
+        if indexPath.row + 5 >= movieSearcher.hits.count {
+            movieSearcher.loadMore()
         }
         
         // Configure the cell...
-        let movie = movies[indexPath.row]
+        let movie = MovieRecord(json: movieSearcher.hits[indexPath.row])
         cell.textLabel?.highlightedTextColor = UIColor(red:1, green:1, blue:0.898, alpha:1)
         cell.textLabel?.highlightedText = movie.title_highlighted
         

    // MARK: - Search bar
    
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        query.query = searchController.searchBar.text
        let curSearchId = searchId
        
        movieIndex.search(query, completionHandler: { (data, error) -> Void in
            if (curSearchId <= self.displayedSearchId) || (error != nil) {
                return
            }
            
            self.displayedSearchId = curSearchId
            self.loadedPage = 0 // reset loaded page
            self.loadingPage = 0 // reset the loading page
            
            guard let
                hits = data?["hits"] as? [[String: AnyObject]],
                nbPages = data?["nbPages"] as? UInt
            else {
                return
            }
            self.nbPages = nbPages
            
            var tmp = [MovieRecord]()
            for hit in hits {
                tmp.append(MovieRecord(json: hit))
            }
            
            self.movies = tmp
            self.tableView.reloadData()
        })
        
        self.searchId += 1
    }
    
    // MARK: - Load more
    
    func loadMore() {
        if loadedPage + 1 >= nbPages {
            return
        }
        // check if already loading this page so a redundent query isn't generated
        if loadedPage + 1 == loadingPage {
            return
        }
        loadingPage = loadedPage + 1
        
        let nextQuery = Query(copy: query)
        nextQuery.page = loadedPage + 1
        movieIndex.search(nextQuery, completionHandler: { (data , error) -> Void in
            // Reject if query has changed
            if (nextQuery.query != self.query.query) || (error != nil) {
                return
            }
            
            self.loadedPage = nextQuery.page!.unsignedIntegerValue
            
            guard let hits = data?["hits"] as? [[String: AnyObject]] else {
                return
            }
            var tmp = [MovieRecord]()
            for hit in hits {
                tmp.append(MovieRecord(json: hit))
            }
            
            self.movies.appendContentsOf(tmp)
            self.tableView.reloadData()
        })
    }

}

        tableView.tableHeaderView = self.searchController!.searchBar
        definesPresentationContext = true
        searchController!.searchBar.sizeToFit()
        
        // First load
        updateSearchResultsForSearchController(searchController)
