     }
     
     func changeNumPins() {
+        guard let placeArray = placeArray, placeArray.count > 0 else { return }
         removeExistingPins()
-        
-        let end = min(placeArray!.count, numResults)
+        let end = min(placeArray.count, numResults)
         print("placing \(end) pins")
-        self.addPlaces(places: Array(placeArray![..<end]))
+        self.addPlaces(places: Array(placeArray[..<end]))
     }
     
     func removeExistingPins() {

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

                
                // Add an AR node and map view annotation for every defined "step" in the route
                for step in leg.steps {
                    if let coordinate = step.coordinates?.first {
                        polyline.append(coordinate)
                        let stepLocation = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)
                        
                        // Update feature collection for map view
                        self.updateShapeCollectionFeature(&self.waypointShapeCollectionFeature, with: stepLocation, typeKey: "waypoint-type", typeAttribute: "big")
                        
                        // Add an AR node
                        let annotation = Annotation(location: stepLocation, calloutImage: self.calloutImage(for: step.description), place: nil)
                        annotationsToAdd.append(annotation)
                    }
                }
                
                let metersPerNode: CLLocationDistance = 5
