     //}
     
     func setupKeys() {
+        if self.layout == nil {
+            return
+        }
+        
         for page in keyboard.pages {
             for rowKeys in page.rows { // TODO: quick hack
                 for key in rowKeys {
-                    var keyView = self.layout.viewForKey(key)! // TODO: check
+                    var keyView = self.layout!.viewForKey(key)! // TODO: check
                     
                     let showOptions: UIControlEvents = .TouchDown | .TouchDragInside | .TouchDragEnter
                     let hideOptions: UIControlEvents = .TouchUpInside | .TouchUpOutside | .TouchDragOutside

            let charactersAreInCorrectState = { () -> Bool in
                let previousContext = (self.textDocumentProxy as? UITextDocumentProxy)?.documentContextBeforeInput
                
                if previousContext == nil || countElements(previousContext!) < 2 {
                    return false
                }
                

    
    var keyboard: Keyboard!
    var forwardingView: ForwardingView
    var layout: KeyboardLayout?
    var heightConstraint: NSLayoutConstraint?
    
    var bannerView: BannerView?
