diff --git a/persiantools.module b/persiantools.module
index d3f4184..c742b02 100644
--- a/persiantools.module
+++ b/persiantools.module
@@ -1,4 +1,17 @@
 <?php
+const S_NA = 0;
+const S_FA = 1;
+const S_EN = 2;
+const S_PUNCT = 3;
+const S_OPENING = 4;
+const S_CLOSED = 5;
+const S_RTL = 0;
+const S_LTR = 1;
+const S_DIGIT = 6;
+const S_EOL = 7;
+const S_SLASH = 8;
+const S_WS = 9;
+const IS_ALL_EN = TRUE;
 
 /**
  * @file
@@ -79,16 +92,12 @@ function persiantools_preprocess_html(&$variables) {
 function persiantools_convert_sm($str) {
   $opening_syms = array('(', '{', '[', '"', '\'');
   $fa_digits = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');
-  $s_rtl = 0; $s_ltr = 1;
-  $s_na = 0; $s_fa = 1; $s_en = 2; $s_punct = 3; $s_opening = 4; $s_closed = 5;
-  $s_digit = 6; $s_eol = 7; $s_slash = 8; $s_ws = 9;
-  $is_all_en = TRUE;
   $maybe_path = TRUE; $is_path = FALSE; $path_pos = -1;
   $digit_method = variable_get('digit_method');
   $rtl_ltr_fix = variable_get('rtl_ltr_fix');
   $closing_ch = '\0'; $paren_state = 0;
-  $prev_ch_type = $s_na;
-  $dir = $s_rtl;
+  $prev_ch_type = S_NA;
+  $dir = S_RTL;
   $len = strlen($str);
   for ($i = 0; $i < $len; $i = $i + 1) {
     // Skip unicode characters, which might be mistaken for english characters
@@ -108,33 +117,33 @@ function persiantools_convert_sm($str) {
     // Detect character type.
     $ch = $str[$i];
     if (($ch >= 'آ' && $ch <= 'ي') || $ch == 'ی') {
-      $type = $s_fa;
+      $type = S_FA;
       $is_all_en = FALSE;
     }
     elseif (($ch >= 'a' && $ch <= 'z') || ($ch >= 'A' && $ch <= 'Z')) {
-      $type = $s_en;
+      $type = S_EN;
     }
     elseif ($ch == $closing_ch) {
-      $type = $s_closed;
+      $type = S_CLOSED;
     }
     elseif (in_array($ch, $opening_syms)) {
-      $type = $s_opening;
+      $type = S_OPENING;
     }
     elseif ($ch >= '0' && $ch <= '9') {
-      $type = $s_digit;
+      $type = S_DIGIT;
     }
     elseif ($ch == '.' || $ch == "!" || $ch == ';' || $ch == '?') {
-      $type = $s_eol;
+      $type = S_EOL;
     }
     elseif ($ch == '/') {
-      $type = $s_slash;
+      $type = S_SLASH;
     }
     elseif ($ch == ' ' || $ch == '\n') {
-      $type = $s_ws;
+      $type = S_WS;
     }
     else {
       // Type not detected.
-      $type = $s_na;
+      $type = S_NA;
       // Last char should go through anyway, to wrap things up.
       if ($i != $len - 1) {
         continue;
@@ -144,11 +153,11 @@ function persiantools_convert_sm($str) {
     // Fix paths in rtl text.
     // TODO: Path-specific setting?
     if ($rtl_ltr_fix) {
-      if ($type == $s_ws) {
+      if ($type == S_WS) {
         $maybe_path = TRUE;
       }
       elseif ($is_path) {
-        if ($type == $s_en) {
+        if ($type == S_EN) {
           $str = persiantools_insert_str($str, '&lrm;', $path_pos);
           $i += 5;
           $len += 5;
@@ -157,7 +166,7 @@ function persiantools_convert_sm($str) {
         $is_path = FALSE;
       }
       elseif ($maybe_path) {
-        if ($type == $s_slash) {
+        if ($type == S_SLASH) {
           $is_path = TRUE;
           if ($path_pos < 0) {
             $path_pos = $i;
@@ -176,10 +185,10 @@ function persiantools_convert_sm($str) {
       }
 
       // Detect trailing slashes in paths.
-      if ($type == $s_slash && $i > 0) {
+      if ($type == S_SLASH && $i > 0) {
         $prev_ch = $str[$i - 1];
         $is_last_char = ($i == $len - 1);
-        if ($prev_ch_type == $s_en && ($is_last_char || $str[$i + 1] == ' ')) {
+        if ($prev_ch_type == S_EN && ($is_last_char || $str[$i + 1] == ' ')) {
           $str = persiantools_insert_str($str, '&lrm;', $i + 1);
           $i += 5;
           $len += 5;
@@ -187,8 +196,8 @@ function persiantools_convert_sm($str) {
       }
     }
     switch ($type) {
-      case $s_digit:
-        if ($digit_method == 'full' || ($digit_method == 'smart' && $dir == $s_rtl)) {
+      case S_DIGIT:
+        if ($digit_method == 'full' || ($digit_method == 'smart' && $dir == S_RTL)) {
           $new_digit = $fa_digits[$ch - '0'];
           $str = substr($str, 0, $i) . $new_digit . substr($str, $i + 1);
           $len += strlen($new_digit) - 1;
@@ -196,15 +205,15 @@ function persiantools_convert_sm($str) {
         }
         break;
 
-      case $s_en:
-        $dir = $s_ltr;
+      case S_EN:
+        $dir = S_LTR;
         break;
 
-      case $s_fa:
-        $dir = $s_rtl;
+      case S_FA:
+        $dir = S_RTL;
         break;
 
-      case $s_opening:
+      case S_OPENING:
         $opening_pos = $i;
         $paren_state = 1;
         break;
@@ -219,24 +228,24 @@ function persiantools_convert_sm($str) {
           break;
 
         case 2:
-          if ($type == $s_closed) {
+          if ($type == S_CLOSED) {
             // Fix misplaced empty enclosing chars, like function calls, array
             // access, ...
-            if ($dir == $s_ltr) {
+            if ($dir == S_LTR) {
               $str = persiantools_insert_str($str, '&lrm;', $i + 1);
               $len += 5;
               $i += 5;
             }
             $paren_state = 0;
           }
-          elseif ($type == $s_en || $type == $s_fa) {
+          elseif ($type == S_EN || $type == S_FA) {
             $post_open = $dir;
             $paren_state = 3;
           }
           break;
 
         case 3:
-          if ($type == $s_closed) {
+          if ($type == S_CLOSED) {
             $pre_close = $dir;
             $paren_state = 4;
             $closed_pos = $i;
@@ -244,14 +253,14 @@ function persiantools_convert_sm($str) {
           break;
 
         case 4:
-          if ($type == $s_en || $type == $s_fa) {
+          if ($type == S_EN || $type == S_FA) {
             $post_close = $dir;
             $paren_state = 5;
           }
           break;
       }
       if ($paren_state == 4 && ($i == $len - 1)) {
-        $post_close = $s_rtl;
+        $post_close = S_RTL;
         $paren_state = 5;
       }
       if ($paren_state == 5) {
@@ -259,21 +268,21 @@ function persiantools_convert_sm($str) {
           $open_dir = $pre_open;
         }
         else {
-          $open_dir = $s_rtl;
+          $open_dir = S_RTL;
         }
         if ($pre_close == $post_close) {
           $close_dir = $pre_close;
         }
         else {
-          $close_dir = $s_rtl;
+          $close_dir = S_RTL;
         }
         if ($open_dir != $close_dir) {
-          if ($pre_open == $s_rtl) {
+          if ($pre_open == S_RTL) {
             $str = persiantools_insert_str($str, '&rlm;', $closed_pos);
             $len += 5;
             $i += 5;
           }
-          elseif ($pre_open == $s_ltr) {
+          elseif ($pre_open == S_LTR) {
             // &#8234; lre (Left to Right Embedding).
             // &#8236: pdf (Pop Directional Formatting).
             $str = persiantools_insert_str($str, '&#8234;', $opening_pos);
@@ -285,7 +294,7 @@ function persiantools_convert_sm($str) {
         }
       }
       // Fix misplaced dot in English Sentences inside RTL direction.
-      if ($is_all_en && $dir == $s_ltr && $type == $s_eol) {
+      if ($is_all_en && $dir == S_LTR && $type == S_EOL) {
         $str = persiantools_insert_str($str, '&lrm;', $i + 1);
         $i += 5;
         $len += 5;
@@ -300,18 +309,19 @@ function persiantools_convert_sm($str) {
  * Returns the matching closing char for an opening char.
  */
 function persiantools_get_closing_char($char) {
-  if ($char == '(') {
-    return ')';
-  }
-  elseif ($char == '{') {
-    return '}';
-  }
-  elseif ($char == '[') {
-    return ']';
-  }
-  elseif ($char == '\'' || $char == '"') {
-    return $char;
-  }
+    $map=array(
+        '('=>')',
+        '{'=>'}',
+        '['=>']',
+        //@todo remove
+        '\''=>'\'',
+        //@todo remove
+        '"'=>'"',
+    );
+    //throw exception for not accepted inputs
+    if(!key_exists($char,$map)) throw new Exception('character is not accepted');
+    //returns an output for accepted inputs
+    return $map[$char];
 }
 
 /**
