                         type = subJson["t"].string!
                     }
                     
-                    
-                    self.chatMessageData[i] = [subJson["u","_id"].string!, subJson["u","username"].string!, subJson["msg"].string!,type]
                     let timestamp = [subJson["ts","$date"].number!]
                     let timestampInDouble = timestamp as! [Double]
-                    self.ts[i] =  [timestampInDouble[0] / 1000]
+                    let timestampInMilliseconds = timestampInDouble[0] / 1000
+                    
+                    let  cM = ChatMessage(user_id: subJson["u","_id"].string!, username: subJson["u","username"].string!, msg: subJson["msg"].string!, msgType: type, ts: timestampInMilliseconds)
+                    
+                    
+                    self.chatMessageData[i] = cM
+
                     i--
                 }
-                
-                
-                
-                //                for (var i = 0; i<self.chatMessageData.count; i++){
-                //                    print("\(self.chatMessageData[i])\n")
-                //                }
                 
                 
                 //Reload data and scroll to the bottom of the tableview

        //Create double tap gesture
        let doubleTapGesture = UITapGestureRecognizer(target: self, action: Selector("showHiddenTimestamp:"))
        doubleTapGesture.numberOfTapsRequired = 2
//
        //Add gestures on tableview
        mainTableview.addGestureRecognizer(tapGesture)
        mainTableview.addGestureRecognizer(doubleTapGesture)

        }
        
        //Get the 50 past messages to fill the tableview
        let now = NSDate()
        
        let formData = NSDictionary(dictionary: [
