         tableView.deselectRowAtIndexPath(indexPath, animated:true)
         
         let cell = tableView.cellForRowAtIndexPath(indexPath)
+        
         if let x = cell as? FlexibleTableViewCell {
-            if x.expandable {
-                x.expanded = !x.expanded
-                
-                var _indexPath = indexPath
-                let correspondingIndexPath = correspondingIndexPathForRowAtIndexPath(_indexPath)
-                if (x.expanded && shouldExpandOnlyOneCell) {
-                    _indexPath = correspondingIndexPath.ns;
-                    collapseCurrentlyExpandedIndexPaths()
-                }
-                
-                let numberOfSubRows = numberOfSubRowsAtIndexPath(correspondingIndexPath.ns)
-                
-                var expandedIndexPaths = [NSIndexPath]()
-                let row = _indexPath.row;
-                let section = _indexPath.section;
-                
-                for var index = 1; index <= numberOfSubRows; index++ {
-                    let expIndexPath = NSIndexPath(forRow:row+index, inSection:section)
-                    expandedIndexPaths.append(expIndexPath)
-                }
-                
-                if (x.expanded)
-                {
-                    setExpanded(true, forCellAtIndexPath:correspondingIndexPath)
-                    insertRowsAtIndexPaths(expandedIndexPaths, withRowAnimation:UITableViewRowAnimation.Top)
-                }
-                else
-                {
-                    setExpanded(false, forCellAtIndexPath:correspondingIndexPath)
-                    deleteRowsAtIndexPaths(expandedIndexPaths, withRowAnimation:UITableViewRowAnimation.Top)
-                }
-                
-                x.accessoryViewAnimation()
-            }
-            
-            if flexibleTableViewDelegate.respondsToSelector("tableView:didSelectRowAtIndexPath:") {
-                let correspondingIndexPath = correspondingIndexPathForRowAtIndexPath(indexPath)
-                
-                if (correspondingIndexPath.subRow == 0) {
-                    flexibleTableViewDelegate.tableView!(self, didSelectRowAtIndexPath:correspondingIndexPath.ns)
-                } else {
-                    flexibleTableViewDelegate.tableView!(self, didSelectSubRowAtIndexPath:correspondingIndexPath.ns)
-                }
-            }
-            
-        }
-        else
-        {
-            if flexibleTableViewDelegate.respondsToSelector("tableView:didSelectSubRowAtIndexPath:"){
-                let correspondingIndexPath = correspondingIndexPathForRowAtIndexPath(indexPath)
-                
-                flexibleTableViewDelegate.tableView!(self, didSelectSubRowAtIndexPath:correspondingIndexPath.ns)
-            }
+            
+            if !x.expandable { return }
+            
+            x.expanded = !x.expanded
+            
+            var _indexPath = indexPath
+            let correspondingIndexPath = correspondingIndexPathForRowAtIndexPath(_indexPath)
+            if (x.expanded && shouldExpandOnlyOneCell) {
+                _indexPath = correspondingIndexPath.ns;
+                collapseCurrentlyExpandedIndexPaths()
+            }
+            
+            let numberOfSubRows = numberOfSubRowsAtIndexPath(correspondingIndexPath.ns)
+            
+            var expandedIndexPaths = [NSIndexPath]()
+            let row = _indexPath.row;
+            let section = _indexPath.section;
+            
+            for var index = 1; index <= numberOfSubRows; index++ {
+                let expIndexPath = NSIndexPath(forRow:row+index, inSection:section)
+                expandedIndexPaths.append(expIndexPath)
+            }
+            
+            if (x.expanded)
+            {
+                setExpanded(true, forCellAtIndexPath:correspondingIndexPath)
+                insertRowsAtIndexPaths(expandedIndexPaths, withRowAnimation:UITableViewRowAnimation.Top)
+            }
+            else
+            {
+                setExpanded(false, forCellAtIndexPath:correspondingIndexPath)
+                deleteRowsAtIndexPaths(expandedIndexPaths, withRowAnimation:UITableViewRowAnimation.Top)
+            }
+            
+            x.accessoryViewAnimation()
+            
+            flexibleTableViewDelegate.tableView?(self, didSelectRowAtIndexPath:indexPath)
+            
+        } else {
+            let correspondingIndexPath = correspondingIndexPathForRowAtIndexPath(indexPath)
+            
+            flexibleTableViewDelegate.tableView?(self, didSelectSubRowAtIndexPath:correspondingIndexPath)
         }
     }
     

        return 0.0
    }
    public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        if flexibleTableViewDelegate.respondsToSelector("tableView:titleForHeaderInSection:") {
            return flexibleTableViewDelegate.tableView!(self, titleForHeaderInSection: section)
        }
        return nil
    }
    public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
        return flexibleTableViewDelegate.tableView?(self, titleForFooterInSection: section)

    func tableView(tableView: UITableView, numberOfSubRowsAtIndexPath indexPath: NSIndexPath) -> Int
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    func tableView(tableView: UITableView, cellForSubRowAtIndexPath indexPath: FlexibleIndexPath) -> UITableViewCell
    optional func numberOfSectionsInTableView(tableView: UITableView) -> Int
    optional func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    optional func tableView(tableView: UITableView, heightForSubRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    optional func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    optional func tableView(tableView: FlexibleTableView, didSelectSubRowAtIndexPath indexPath: FlexibleIndexPath)
    optional func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
    optional func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
    optional func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
