 // Functions
 void setReference();
 void GPSData();
+void modem_initialization(void);
+void send_message(void);
+void command_match(void);
+void gsm_read_message();
 //void ring();
 /*******************************************************************************************
 Function Name: Setup
 *******************************************************************************************/
 void setup() {
+  delay(3000);
+  //Serial.begin(9600);
   Serial1.begin(9600); // initialize serial communication for BT
   GPS.begin(9600); // initialize serial communication for GPS
-  //GSMmodule.begin(9600); // initialize serial communication for GSM
+  GSMmodule.begin(9600); // initialize serial communication for GSM
   
-  // initialize device
   Serial1.println("Initializing IMU device...");
-  CurieIMU.begin();
-
-  // Set the accelerometer range to 3G
-  CurieIMU.setAccelerometerRange(3);
+  CurieIMU.begin(); // initialize device
+  CurieIMU.setAccelerometerRange(3); // Set the accelerometer range to 3G
+
+  Serial1.println("Modem initializing");
+  modem_initialization(); // initialize GSM modem
+  Serial1.println("Modem initialised");
   delay(1000);
 }
 /*******************************************************************************************
 Function Name: Loop
 *******************************************************************************************/
 void loop() {
+  gsm_read_message();//wait for message or call
+  if ( reply_flag == 1 ) //only if valid message received
+  {
+    Serial1.println(message);
+    command_match();
+    reply_flag = 0;
+  }
   //ring();
   if (Serial1.available() > 0) {
     char ch = Serial1.read();

  noTone(8);
  delay(100);
}*/


Function Name: GPSData
*******************************************************************************************/
void GPSData() {
  //while (!finish) {
  //Serial1.println(GPS.available());
    while (GPS.available() > 0) {       // Check GPS data
      Gpsdata = GPS.read();
      //Serial1.write(Gpsdata);
