 
     let monitoringDuration = abs(locationUpdateStartTime?.timeIntervalSinceNow ?? 0)
     log.debug("Location monitoring stopped after \(monitoringDuration) seconds and \(self.locations.count) locations")
-    locationManager?.stopUpdatingLocation()
+    locationManager.stopUpdatingLocation()
     let initialLocation = CLLocation()
     var bestLocation: CLLocation? =
     locations.reduce(nil as CLLocation?) { (best, candidate) in


  func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    locationManager?.stopUpdatingLocation()
  }
  
  func applicationDidReceiveMemoryWarning(application: UIApplication) {


    if status == .AuthorizedWhenInUse {
      
      locationManager.delegate = self
      locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
      locationManager.activityType = CLActivityType.AutomotiveNavigation
      locationManager.distanceFilter = 10 // meters
      
      startUpdatingLocationForWhile()

    } else {
      // User disapproved location updates so make sure that we no more use it
      locationManager.stopUpdatingLocation()
      locationManager.stopMonitoringSignificantLocationChanges()
      log.error("Location service not authorized by the user")
      locationServiceDisabledAlert(authorizationStatus: status)
    }
