     
     var location = ""
     let defaults = UserDefaults.standard
+    
+    var timer: Timer?
 
     override func viewDidLoad() {
         super.viewDidLoad()

                    return
                }
                
                log.debug(json)
                
                let weatherList = json["list"].arrayValue.map { (data) -> Weather in
                    let timestamp = data["dt"].uInt64Value

        
        loadWeather(location: location)
        loadForecast(location: location)
        
        setupTimer()
        defaults.addObserver(self, forKeyPath: "refreshInterval", options: .new, context: nil)
    }
    
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if keyPath != "refreshInterval" {
            return
        }
        DispatchQueue.main.async {
            self.setupTimer()
        }
    }
    
    func setupTimer() {
        log.debug("Setting up timer")
        let serializedInterval = defaults.object(forKey: "refreshInterval") as? UInt
        var interval: RefreshInterval = .perMinute(5)
        if let si = serializedInterval, let i = RefreshInterval.parse(serialized: si) {
            interval = i
        }
        log.debug("Interval: \(interval.toString())")
        if let timer = timer {
            timer.invalidate()
        }
        timer = Timer.scheduledTimer(withTimeInterval: interval.toTimeInterval(), repeats: true, block: { _ in
            log.info("Refreshing weather data")
            self.loadWeather(location: self.location)
            self.loadForecast(location: self.location)
        })
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        if isMovingFromParentViewController {
            log.debug("Going back to search")
