diff --git a/smsmsg91.module b/smsmsg91.module
index a6cc9c1..dc58bfa 100644
--- a/smsmsg91.module
+++ b/smsmsg91.module
@@ -105,44 +105,74 @@ function smsmsg91_sms_form_submit($form, &$form_state) {
   // Define route.
   $route = variable_get('smsmsg91_route');
   // Prepare you post parameters.
-  $postData = array(
-    'authkey' => $authKey,
-    'mobiles' => $mobileNumber,
-    'message' => $message,
-    'sender' => $senderId,
-    'route' => $route,
-  );
+  // Function for sending message.
+  smsmsg91_send_message($mobileNumber, $message, $senderId, $route)
+
+  // To be decided $form_state['redirect'] = '/';.
+}
+
+/**
+ * Function for sending SMS.
+ */
+function smsmsg91_send_message($mobileNumber, $message, $senderId, $route) {
 
-  // API URL.
-  $url = "https://control.msg91.com/api/sendhttp.php";
-
-  // Init the resource.
-  $ch = curl_init();
-  curl_setopt_array($ch, array(
-    CURLOPT_URL => $url,
-    CURLOPT_RETURNTRANSFER => TRUE,
-    CURLOPT_POST => TRUE,
-    CURLOPT_POSTFIELDS => $postData,
-        // ,CURLOPT_FOLLOWLOCATION => true.
-  ));
-
-  // Ignore SSL certificate verification.
-  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-
-  // Get response.
-  $output = curl_exec($ch);
-
-  // Print error if any.
-  if (curl_errno($ch)) {
-    echo 'error:' . curl_error($ch);
+  if (empty($mobileNumber)) {
+    watchdog('SMSMSG91', 'Please send mobile number for sending SMS', WATCHDOG_ERROR);
+    return FALSE;
+  }
+  if (empty($senderId)) {
+    $senderId = variable_get('smsmsg91_senderID');
+  }
+  if (empty($route)) {
+    $route = variable_get('smsmsg91_route');
   }
 
-  curl_close($ch);
+  $authKey = variable_get('smsmsg91_authKey', '');
 
-  echo $output;
+  if (!empty($authKey)) {
 
-  drupal_set_message('SMS Sent');
+    $postData = array(
+      'authkey' => $authKey,
+      'mobiles' => $mobileNumber,
+      'message' => $message,
+      'sender' => $senderId,
+      'route' => $route,
+    );
+
+    // API URL.
+    $url = "https://control.msg91.com/api/sendhttp.php";
+
+    // Init the resource.
+    $ch = curl_init();
+    curl_setopt_array($ch, array(
+      CURLOPT_URL => $url,
+      CURLOPT_RETURNTRANSFER => TRUE,
+      CURLOPT_POST => TRUE,
+      CURLOPT_POSTFIELDS => $postData,
+          // ,CURLOPT_FOLLOWLOCATION => true.
+    ));
+
+    // Ignore SSL certificate verification.
+    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+
+    // Get response.
+    $output = curl_exec($ch);
+
+    // Print error if any.
+    if (curl_errno($ch)) {
+      watchdog('SMSMSG91', 'Error while sending SMS');
+      echo 'error:' . curl_error($ch);
+    }
+
+    curl_close($ch);
+    drupal_set_message('SMS Sent');
+    watchdog('SMSMSG91', 'SMS sent to Mobile Number %mobileNumber', array('%mobileNumber' => $mobileNumber));
+
+  }
+  else {
+    watchdog('SMSMSG91', 'Please set authkey for MSG91 in order to send SMS', WATCHDOG_ERROR);
+    return FALSE;
+  }
 
-  // To be decided $form_state['redirect'] = '/';.
 }
