                     display.text="0"
                 }
                 else{
-                display.text="\(newValue!)"
+                    display.text="\(newValue!)"
                 }
             }
             userInMiddleOfTypingNumber=false
         }
     }
     
-    var historyValue:String{
+    var historyValue:String?{
         get{
-            if let text = history.text {
-                return text
-            }
-            else{
-                return ""
-            }
+            return history.text
         }
         set{
-            if history.text!.rangeOfString("=") != nil{
-                history.text = newValue
+            if history.text?.rangeOfString("=") != nil || newValue == "" || history.text==nil{
+                history.text = ""
             }
-            else if newValue == ""{
-                history.text = newValue
-            }
-            else {
-                history.text = history.text! + newValue
-            }
+            
+            history.text = (newValue ?? "")
         }
     }
 }

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

            brain.pushOperation(operation)
            displayValue=0
            
            historyValue = (historyValue ?? "") + operation
        }
    }
    
