             display.text = (userInMiddleOfTypingNumber ? display.text!+digit : digit)
             userInMiddleOfTypingNumber=true
             
-            historyValue = digit
+            historyValue = (historyValue ?? "") + digit
         }
     }
     
     @IBAction func appendFloatingPoint() {
         if display.text!.rangeOfString(".")==nil{
             display.text=display.text!+"."
-            historyValue = "."
+            historyValue = (historyValue ?? "") + "."
             userInMiddleOfTypingNumber=true
         }
     }
     
     @IBAction func undoDigit() {
-        if var displayString = display.text, var historyString = history.text{
+        if var displayString = display.text, var historyString = historyValue{
             if(count(displayString)==1)
             {
                 displayValue=0

        formatter.locale = NSLocale(localeIdentifier: "en_US")
        return formatter.numberFromString(self)?.doubleValue
    }
}


        }
        if let result=brain.evaluate(){
            displayValue=result
            historyValue = (historyValue ?? "") + "="
        }
        else{
            display.text = "Error"
