diff --git a/content_pager.module b/content_pager.module
index 3295636..51bda7d 100644
--- a/content_pager.module
+++ b/content_pager.module
@@ -9,6 +9,9 @@
  * @param $variables
  * Get the values of content, type, word_count, character_count
  */
+
+use Drupal\Component\Utility\Unicode;
+
 function content_pager_preprocess_node(&$variables) {
     if($node = \Drupal::routeMatch()->getParameter('node')) {
         $nid = $node->id();
@@ -40,7 +43,7 @@ function content_pager_preprocess_node(&$variables) {
              ->get('content_pager.automaticMethod_' . $typeId);
            $paging_auto_method_words = \Drupal::config('content_pager.automaticMethodWords_' . $typeId)
              ->get('content_pager.automaticMethodWords_' . $typeId);
-           $orphan_words_limit = \Drupal::config('paging.automaticMethodWordsOrphan_' . $typeId)
+           $orphan_words_limit = \Drupal::config('content_pager.automaticMethodWordsOrphan_' . $typeId)
              ->get('content_pager.automaticMethodWordsOrphan_' . $typeId);
            $paging_auto_method_chars = \Drupal::config('content_pager.automaticMethodChars_' . $typeId)
              ->get('content_pager.automaticMethodChars_' . $typeId);
@@ -66,7 +69,8 @@ function content_pager_preprocess_node(&$variables) {
                    $bodypart = array();
 
                    for ($i = 0; $i <= $breaks; $i++) {
-
+                // Pick off the next body part.
+                       $bodypart[$i]  = Unicode::truncate($body, $max_chars, TRUE, TRUE);
                        // Now pull that off the body.
                        $bodycount = strlen($bodypart[$i]);
                        $body = substr($body, $bodycount);
@@ -79,11 +83,94 @@ function content_pager_preprocess_node(&$variables) {
                            break;
                        }
                    }
+
                    $body_parts = implode($paging_separator, $bodypart);
                }
            }
+           // Automatic paging based on word count.
+           elseif ($paging_auto_method == 'words'  && ($max_words = $paging_auto_method_words) != 0) {
+
+               $orphan_size =$orphan_words_limit;
+               $words = explode(' ', $body);
+               $total_words = count($words);
+               $words_remaining = $total_words - $max_words;
+
+               // Check if pagination is possible.
+               if ($total_words > $max_words) {
+                   $breaks = (int)($total_words / $max_words);
+                   for ($i = 1; $i < $breaks; $i++) {
+                       $index = $i * $max_words;
+                       $words_remaining -= $max_words;
+
+                       // Orphan check.
+                       if ($words_remaining < $orphan_size) {
+                           drupal_set_message(t('Page @num would be an orphan; keeping with last page.',
+                               array('@num' => $i + 1)), 'status', FALSE);
+                       }
+                       else {
+                           // Not an orphan, treat normally.
+                           $words[$index] .= $paging_separator;
+                       }
+                   }
+               }
+              $body_parts = implode(' ', $words);
+           }
+
            $node->pages = explode($paging_separator, $body_parts);
            $node->page_count = count($node->pages);
+//pagination starts
+
+
+// If paging is enabled for this node type.
+           if ($paging_enabled == TRUE) {
+               // Get the paging field name.
+               $field = $paging_field;
+               // Set an element value for this pager.
+               $element = 0;
+               // Pull page from the URL query string.
+               $page = isset($_GET['page']) ? $_GET['page'] : '';
+               // Only do paging
+               if ($node->page_count > 1 && $page != 'full') {
+
+                   pager_default_initialize($node->page_count, 1, $element);
+
+                   // Store the page in here, for safe keeping.
+                   $current_page = explode(',', $page);
+                   // Clean up page number for use later on.
+                   $page = ($current_page[$element] != '') ? $current_page[$element] : 0 ;
+                   // Put the current page contents into the body.
+                   $lang = isset($node->{$field}[$node->language]) ? $node->language : LANGUAGE_NONE;
+                   $format = $node->{$field}[$lang][0]['format'];
+                   $node->content[$field][0]['#markup'] = check_markup($node->pages[$page], $format, FALSE);
+
+                   // Mapping the pages in $node->page_names and $node->page_count to set number of pages as the array length.
+                   $fake = array_fill(0, ($node->page_count - 1) + 1, '');
+                   $length = count($fake) > count($node->page_names) ? count($fake) : count($node->page_names);
+                   for ($i=0; $i<$length; ++$i) {
+                       $merged[$i] = array_key_exists($i, $node->page_names) ? $node->page_names[$i] : '';
+                   }
+                   // Fill the empty names with node title and page number.
+                   //    $node->page_names = _paging_populate_empty_names($merged, $node->title); // Uncomment
+
+                   // Generate the pager.
+                   //  $pager = theme('pager', array('element' => $element)); // Uncomment
+
+                   // Add pager to node content.
+                   //   $node->content['paging']['#markup'] = $pager;   // Uncomment
+                   // Add the second pager if requested.
+                   $setting = $paging_pager_Count;
+                   if ($setting == 'two') {
+                       //        $node->content['paging_above']['#markup'] = $pager;
+                   }
+
+                   if ($paging_changetitle && !empty($page)) {
+                       // Set the browser title to page's name.
+                       drupal_set_title(t($node->page_names[$page]));
+                   }
+               }
+           }
+//pagination ends
+
 
        }
     }
