             self.popupDirection = Direction.Up
             self.setupPopupConstraints(self.popupDirection)
             self.configurePopup(self.popupDirection)
-            
-//            if self.popup!.frame.height < 20 {
-//            NSLog("popup frame is \(NSStringFromCGRect(self.popup!.frame))")
-            
-            var popupPosition = self.superview.convertPoint(self.popup!.frame.origin, fromView: self)
-            popupPosition.y = popupPosition.y - self.popup!.frame.height
-            NSLog("popup positio is \(NSStringFromCGPoint(popupPosition))")
-            
-            if popupPosition.y < 13 {
+            super.layoutSubviews()
+            
+            var upperLeftCorner = self.popup!.frame.origin
+            var popupPosition = self.superview.convertPoint(upperLeftCorner, fromView: self)
+            
+//            if popupPosition.y < 0 {
+            if self.popup!.bounds.height < 10 {
                 if self.frame.origin.x < self.superview.bounds.width/2 {
                     self.popupDirection = Direction.Right
                 }
                 else {
                     self.popupDirection = Direction.Left
                 }
-                
                 self.setupPopupConstraints(self.popupDirection)
                 self.configurePopup(self.popupDirection)
-                
                 super.layoutSubviews()
-                
-                var popupPosition = self.superview.convertPoint(self.popup!.frame.origin, fromView: self)
-                popupPosition.y = popupPosition.y - self.popup!.frame.height
-                NSLog("popup positio is \(NSStringFromCGPoint(popupPosition))")
             }
         }
         

        super.init(frame: frame)
        
        self.clipsToBounds = false
        self.addSubview(self.keyView)
        
        self.ambiguityTimer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: "timerLoop", userInfo: nil, repeats: true)
        

            attribute: (dir.horizontal() ? NSLayoutAttribute.CenterY : NSLayoutAttribute.CenterX),
            multiplier: 1,
            constant: 0)
        centerConstraint.priority = 500
        self.constraintStore += (self, centerConstraint)
        
        for (view, constraint) in self.constraintStore {
