 extension SearchViewController: UITableViewDelegate {
     func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
         var url: NSURL?
-        if indexPath.row < searchSuggestions.count {
-            let suggestion = searchSuggestions[indexPath.row]
-
-            // Assume that only the default search engine can provide search suggestions.
-            url = searchEngines?.defaultEngine.searchURLForQuery(suggestion)
-        } else {
-            let engine = sortedEngines[indexPath.row - searchSuggestions.count]
-            url = engine.searchURLForQuery(searchQuery)
+        if let currentSection = SearchListSection(rawValue: indexPath.section) {
+            switch currentSection {
+            case .SuggestedSites:
+                let suggestion = searchSuggestions[indexPath.row]
+
+                // Assume that only the default search engine can provide search suggestions.
+                url = searchEngines?.defaultEngine.searchURLForQuery(suggestion)
+            case .BookmarksAndHistory:
+                if var hasHistory = history {
+                    if let site = hasHistory[indexPath.row] as? Site {
+                        url = NSURL(string: site.url)
+                    }
+                }
+            case .Search:
+                let engine = sortedEngines[indexPath.row - searchSuggestions.count]
+                url = engine.searchURLForQuery(searchQuery)
+            }
         }
 
         if let url = url {

    private var sortedEngines = [OpenSearchEngine]()
    private var suggestClient: SearchSuggestClient?
    private var searchSuggestions = [String]()
    //Copy from HistoryViewController
    //Since we create profile in didFinishLaunchingWithOptions and hundreds of class instance access profile, why wouldn't we make profile singleton?
    var profile: Profile!
    private var history: Cursor? = nil
    
    var searchEngines: SearchEngines? {
        didSet {

            }

            // Reload the tableView to show the new list of search suggestions.
            self.tableView.reloadData()
        })
    }

    private func queryHistoryClient() {

        if searchQuery.isEmpty {
            history = nil
            return
        }

        let opts = QueryOptions()
        opts.sort = .LastVisit
        opts.filter = searchQuery

        profile.history.get(opts, complete: { (data: Cursor) -> Void in
            if data.status != .Success {
                println("Err: \(data.statusMessage)")
                self.history = nil
            } else {
                self.history = data
            }
            self.tableView.reloadData()
        })
    }
