                 if let places = places {
                     self.removeExistingPins()
                     self.placeArray = places
-                    let end = min(self.placeArray!.count, self.numResults)
-                    self.addPlaces(places: Array(places[..<end]))
+                    if let places = self.placeArray {
+                        let end = min(places.count, self.numResults)
+                        self.addPlaces(places: Array(places[..<end]))
+                    }
                 }
             }, failure: { (error: Error) in
                 print("error fetching places based on search term: \(searchText). Error: \(error)")

        
        // Initiate the query
        let _ = directions.calculate(options) { (waypoints, routes, error) in
            guard error == nil else {
                print("Error calculating directions: \(error!)")
                return
            }
            

                if self.moreControl.selectedSegmentIndex == 1 {
                    self.numResults = 20
                }
                let end = min(places.count, self.numResults)
                self.addPlaces(places: Array(places[..<end]))
            }
        }) { (error: Error) in
