diff --git a/README.txt b/README.txt
index 0b1ff94..9ac289e 100644
--- a/README.txt
+++ b/README.txt
@@ -1,10 +1,71 @@
-Overview
+INTRODUCTION
 --------
+
+This module allows you to add blocks as menu items, e.g. you may place the search block
+inside the main menu.
+
 Drupal 7 port of http://drupal.org/project/menu_inject_block by Andrew M Riley.
 
-Usage
------
+Code Revision to make the version operative by Uli Hake (avevas).
+
+REQUIREMENTS
+------------
+
+This module does not require other modules but it may require that you modify your template.php file
+if it contains a YOURTHEME_menu_link function.
+
+RECOMMENDED MODULES
+-------------------
+
+* Markdown filter (https://www.drupal.org/project/markdown):
+When enabled, display of the project's README.txt help will be rendered
+with markdown.
+
+INSTALLATION
+------------
+
+* Install as you would normally install a contributed Drupal module. See:
+https://drupal.org/documentation/install/modules-themes/modules-7
+for further information.
+
+* Enable the Menu Inject Block module: Administration > Modules (admin/modules)
+
+
+CONFIGURATION
+-------------
+
 1. Add a new menu item or edit an existing one.
-2. Set the path to "<block>"
+2. Set the path to
+
+<block>
+
 3. Choose the block to be injected from the "Block to inject" drop-down.
 4. Save menu item
+5. If your site template (or one of its basetheme ancestors) includes a YOURTHEME_menu_link
+function you have to modify this function. The plugin informs you about this in the
+administration panel of the menu set.
+
+
+To adapt the YOURTHEME_menu_link function in your template.php file, please identify the line of code that configures the menu entry. It will look like this:
+
+$output = l($element['#title'], $element['#href'], $element['#localized_options']);
+
+Once you've identified this line of code you have to implement an "if else" sequence.
+
+The if part renders the Menu Inject Block items and the else part renders standard menu items and includes the detected line of code.
+
+if (isset($element['#original_link']) && isset($element['#localized_options']) && isset($element['#localized_options']['#block_to_render']) && drupal_match_path($element['#original_link']['link_path'], "<block>\n<block>/*")) {
+//Menu Inject Block Items
+$module = $element['#localized_options']['#block_to_render']['module'];
+$delta = $element['#localized_options']['#block_to_render']['delta'];
+$block = block_load($module, $delta);
+$render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
+//use a as html5 placeholder
+$output = '<a>' . render($render_array) . '</a>';
+}
+else {
+//Standard menu items
+$output = l($element['#title'], $element['#href'], $element['#localized_options']);
+}
+return '<li>' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . '</li>\n';
+
diff --git a/menu_inject_block.module b/menu_inject_block.module
index 9c827e0..2fb17b4 100644
--- a/menu_inject_block.module
+++ b/menu_inject_block.module
@@ -1,157 +1,343 @@
 <?php
-
-/**
- * @file
- * Allows blocks to be rendered in place of menu items.
- */
-
-/**
- * Implements hook_menu().
- */
-function menu_inject_block_menu() {
-  $menu_item = array(
-    'page callback' => 'drupal_not_found',
-    'access callback' => TRUE,
-    'type' => MENU_CALLBACK,
-  );
-
-  $items['<block>'] = $menu_item;
-  $items['<block>/%'] = $menu_item;
-
-  return $items;
-}
-
-/**
- * Implements hook_menu_link_alter().
- */
-function menu_inject_block_menu_link_alter(&$item, $menu) {
-  if ($item['module'] == 'menu') {
-    if (drupal_match_path($item['link_path'], "<block>\n<block>/*")) {
-      $item['options']['alter'] = TRUE;
-      $item['options']['unaltered_hidden'] = $item['hidden'];
-
-      if (isset($item['block'])) {
-        $item['options']['block'] = $item['block'];
-      }
+    /**
+     * @file
+     * Allows blocks to be rendered as menu items.
+     */
+    
+    /**
+     * Implements hook_admin_paths().
+     * Needed for setting custom theme in theme settings
+     */
+    function menu_inject_block_admin_paths() {
+        $paths = array();
+        $paths['admin/structure/menu/menutester/*'] = FALSE;
+        return $paths;
     }
-  }
-}
-
-/**
- * Implements hook_translated_menu_link_alter().
- */
-function menu_inject_block_translated_menu_link_alter(&$item, $map) {
-  if (($item['module'] == 'menu') && drupal_match_path($item['link_path'], "<block>\n<block>/*")) {
-    if (isset($item['localized_options']) && isset($item['localized_options']['block'])) {
-      $moddelt = $item['localized_options']['block'];
-      $breakpoint = strpos($moddelt, '-');
-      $module = substr($moddelt, 0, $breakpoint);
-      $delta = substr($moddelt, $breakpoint + 1);
-
-      // We need to render the block beforehand, doing that in theme function
-      // is too late because drupal messages will not work then.
-      $block = block_load($module, $delta);
-      $block_content = _block_render_blocks(array($block));
-      $build = _block_get_renderable_array($block_content);
-      $block_rendered = drupal_render($build);
-
-      $item['block_rendered'] = $block_rendered;
-
-      $item['href'] = 'admin/structure/block/manage/' . $module . '/' . $delta . '/configure';
+    
+    /**
+     * Implements hook_custom_theme().
+     * Display the requested path with the given theme
+     */
+    function menu_inject_block_custom_theme() {
+        if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'menu' && arg(3) == 'menutester' && arg(4) ) {
+            $desired_theme = check_plain(arg(4));
+            return $desired_theme;
+        }
     }
-  }
-}
-
-/**
- * Implements hook_form_alter().
- */
-function menu_inject_block_form_alter(&$form, &$form_state, $form_id) {
-  if ($form_id == 'menu_overview_form') {
-    foreach ($form as $key => $value) {
-      if (isset($value['#item']['href']) && drupal_match_path($value['#item']['href'], "<block>\n<block>/*")) {
-        $item = $value['#item'];
-        $unaltered_hidden = $item['options']['unaltered_hidden'];
-        $form[$key]['#item']['hidden'] = $unaltered_hidden;
-        $form[$key]['hidden']['#default_value'] = !$unaltered_hidden;
-        $form[$key]['#attributes']['class'] = $unaltered_hidden ? 'menu-disabled' : 'menu-enabled';
-        $form[$key]['title']['#value'] = check_plain($item['title']) . ($unaltered_hidden ? ' ('. t('disabled') .')' : '');
-      }
+    
+    /**
+     * Implements hook_menu().
+     */
+    function menu_inject_block_menu() {
+        $menu_item = array(
+                           'page callback' => 'drupal_not_found',
+                           'access callback' => TRUE,
+                           'type' => MENU_CALLBACK,
+                           );
+        
+        $items['<block>'] = $menu_item;
+        $items['<block>/%'] = $menu_item;
+        $defaulttheme = variable_get('theme_default', 'none');
+        if ( $defaulttheme != 'none' ) {
+            $items['admin/structure/menu/menutester/' . $defaulttheme] = array(
+                                                                               'title' => 'Menu Theme Tester',
+                                                                               'description' => 'Test presence of theme_menu_link function in site theme or basetheme(s)',
+                                                                               'page callback' => 'menu_inject_block_test_page',
+                                                                               'access arguments' => array('access administration pages'),
+                                                                               'weight' => 50,
+                                                                               );
+        }
+        return $items;
     }
-  }
-  elseif (($form_id == 'menu_edit_item') && isset($form['link_path'])) {
-	if (isset($form['link_path']['#description'])) {
-      $form['link_path']['#description'] .= t(' Enter %block to have a block displayed.  Don\'t forget to choose which block to display.', array('%block' => '<block>'));
-	}
-
-    if (isset($form['options']['#value']['unaltered_hidden'])) {
-      $form['enabled']['#default_value'] = !$form['options']['#value']['unaltered_hidden'];
+    
+    /**
+     * Menu callback; prints a page listing general help for a module.
+     *
+     * @param $name
+     *   A module name to display a help page for.
+     */
+    function menu_inject_block_test_page() {
+        $output = '';
+        $frontendtheme = variable_get('theme_default', 'none');
+        $output .= '<strong>The menu theme tester will search for a theme_menu_link function in your default theme. If it doesn\'t find one it will also check the base themes if your theme is a subtheme. If the tester detects a _menu_link function that overwrites the built-in Drupal function, you will be informed if you have to modify the function. (Sometimes it may be necessary to flush the server caches of your Drupal system to assure that your template information is up to date.)</strong>';
+        $output .= '<hr />';
+        $output .= '<h3>Test Results</h3>';
+        $found = false;
+        if ( function_exists($frontendtheme . '_menu_link') ) {
+            $found = $frontendtheme;
+        } else {
+            $themes = list_themes();
+            if ( isset($themes[$frontendtheme]->base_theme ) ) {
+                foreach( $themes[$frontendtheme]->base_themes as $theme_machine => $theme_human ) {
+                    if ( function_exists( $theme_machine . '_menu_link' ) ) {
+                        /*
+                         $output .= '<h4>' . t('You have to adapt the %thememachine function in the template.php of the %themehuman!', array( '%thememachine' => $theme_machine . '_link_menu', '%themehuman' => $theme_human ) ) . '</h4>';
+                         $template_file = drupal_get_path('theme', $theme_machine) . '/template.php';
+                         
+                         $output .= '<div>' . t('You can find the template file here: ') . $template_file . '</div>';
+                         */
+                        $found = $theme_machine;
+                        break;
+                    }
+                }
+            }
+        }
+        if ( $found ) {
+            
+            $func = new ReflectionFunction($found . '_menu_link');
+            $filename = $func->getFileName();
+            $start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
+            $end_line = $func->getEndLine();
+            $length = $end_line - $start_line;
+            
+            $source = file($filename);
+            $body = implode("", array_slice($source, $start_line, $length));
+            if ( strpos( $body, '#block_to_render') !== false ) {
+                $output .= '<h4>' . t('Great! Your template.php seems to allow rendering blocks as menu items.') . '</h4>';
+                $template_file = drupal_get_path('theme', $found) . '/template.php';
+                $output .= '<div>' . t('You can find the template file here: ') . $template_file . '</div>';
+                $output .= '<div>' . t( 'This is your current %function function:', array( '%function' => $found . '_menu_link') ) . '</div>';
+                $output .= '<pre>' . check_plain( $body ) . '</pre>';
+                
+            } else {
+                $output .= '<h4>' . t('You have to adapt the %menulink function in the template.php of your theme!', array( '%menulink' => $found . '_menu_link' ) ) . '</h4>';
+                $template_file = drupal_get_path('theme', $found) . '/template.php';
+                $output .= '<div>' . t('You can find the template file here: ') . $template_file . '</div>';
+                
+                $output .= '<div>' . t( 'The current %function should include a line like this one near the end: ', array( '%function' => $found . '_menu_link') ) . "\$output = l(\$element['#title'], \$element['#href'], \$element['#localized_options']);";
+                $output .= '<div>' . t( 'Please find this line inside your current %function:', array( '%function' => $found . '_menu_link') ) . '</div>';
+                $output .= '<pre>' . check_plain( $body ) . '</pre>';
+                $output .= '<div>' . t( 'Once you\'ve found the line you have to adapt it introducing an if-else sequence.' ) . '</div>';
+                $output .= '<div>' . t( 'The if part renders the Menu Inject Block items and the else part renders standard menu items using the line of code you detected.' ) . '</div>';
+                $output .= '<div>' . t( 'The following code is an example. Please back up your original template file before editing.' ) . '</div>';
+                $func = new ReflectionFunction('menu_inject_block_theme_menu_link');
+                $filename = $func->getFileName();
+                $start_line = $func->getStartLine() - 1; // it's actually - 1, otherwise you wont get the function() block
+                $end_line = $func->getEndLine();
+                $length = $end_line - $start_line;
+                
+                $source = file($filename);
+                $body = implode("", array_slice($source, $start_line, $length));
+                $body = str_replace( 'menu_inject_block_theme_menu_link', $found . '_menu_link(Example!!!)', $body );
+                $output .= '<pre>' . check_plain( $body ) . '</pre>';
+                $output .= '<div>' . t('Please consult the <a href="@url">help</a> file of the %module module to obtain more information.', array('%module' => 'Menu Inject Block', '@url' => url('/admin/help/menu_inject_block') ) ) . '</div>';
+            }
+        }
+        
+        return $output;
     }
-  }
-}
-
-/**
- * Implements hook_theme_registry_alter().
- */
-function menu_inject_block_theme_registry_alter(&$theme_registry) {
-  $theme_registry['menu_link']['function'] = 'menu_inject_block_theme_menu_link';
-}
-
-/**
- * Menu link theme function
- */
-function menu_inject_block_theme_menu_link($variables) {
-  $element = $variables['element'];
-  $sub_menu = '';
-
-  if (isset($element['#original_link'])) {
-    $element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];
-  }
-
-  if ($element['#below']) {
-    $sub_menu = drupal_render($element['#below']);
-  }
-
-  $output = '<li' . drupal_attributes($element['#attributes']) . '>';
-
-  if (isset($element['#original_link']['link_path']) && isset($element['#original_link']['link_path']) && drupal_match_path($element['#original_link']['link_path'], "<block>\n<block>/*")) {
-    $output .= $element['#original_link']['block_rendered'];
-  }
-  else {
-    $output .= l($element['#title'], $element['#href'], $element['#localized_options']) . $sub_menu;
-  }
-
-  $output .= "</li>\n";
-
-  return $output;
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function menu_inject_block_form_menu_edit_item_alter(&$form, $form_state) {
-  if (isset($form['options']['#value']['block'])) {
-    $oldblock = $form['options']['#value']['block'];
-  }
-  else {
-    $oldblock = '';
-  }
-
-  $blocks = array('' => t('None'));
-
-  foreach (module_implements('block_info') as $module) {
-    $module_blocks = module_invoke($module, 'block_info');
-    if (!empty($module_blocks)) {
-      foreach ($module_blocks as $delta => $block) {
-        $moduledelta = $module . '-' . $delta;
-        $blocks[$moduledelta] = $block['info'];
-      }
+    
+    
+    /**
+     * Implements hook_menu_link_alter().
+     */
+    function menu_inject_block_menu_link_alter(&$item, $menu) {
+        if ($item['module'] == 'menu') {
+            if (drupal_match_path($item['link_path'], "<block>\n<block>/*")) {
+                $item['options']['alter'] = TRUE;
+                $item['options']['unaltered_hidden'] = $item['hidden'];
+                
+                if (isset($item['block'])) {
+                    $item['options']['#block'] = $item['block'];
+                    $item['options']['#block_to_render'] = [];
+                }
+            }
+        }
+    }
+    
+    /**
+     * Implements hook_translated_menu_link_alter().
+     */
+    function menu_inject_block_translated_menu_link_alter(&$item, $map) {
+        if (($item['module'] == 'menu') && drupal_match_path($item['link_path'], "<block>\n<block>/*")) {
+            if (isset($item['localized_options']) && isset($item['localized_options']['#block'])) {
+                $moddelt = $item['localized_options']['#block'];
+                $breakpoint = strpos($moddelt, '-');
+                $module = substr($moddelt, 0, $breakpoint);
+                $delta = substr($moddelt, $breakpoint + 1);
+                $item['localized_options']['#block_to_render'] = array( 'module' => $module, 'delta' => $delta);
+                $item['href'] = 'admin/structure/block/manage/' . $module . '/' . $delta . '/configure';
+            }
+        }
+    }
+    
+    
+    /**
+     * Implements hook_form_alter().
+     */
+    function menu_inject_block_form_alter(&$form, &$form_state, $form_id) {
+        if ($form_id == 'menu_overview_form') {
+            $bmifound = 0;
+            foreach ($form as $key => $value) {
+                if (isset($value['#item']['href']) && drupal_match_path($value['#item']['href'], "<block>\n<block>/*")) {
+                    $bmifound++;
+                    $item = $value['#item'];
+                    $unaltered_hidden = $item['options']['unaltered_hidden'];
+                    $form[$key]['#item']['hidden'] = $unaltered_hidden;
+                    $form[$key]['hidden']['#default_value'] = !$unaltered_hidden;
+                    $form[$key]['#attributes']['class'] = $unaltered_hidden ? array('menu-disabled') : array('menu-enabled');
+                    $form[$key]['title']['#markup'] = check_plain($item['title']) . ($unaltered_hidden ? ' ('. t('disabled') .')' : '');
+                }
+                if ( isset($value['#item']['href']) && strpos($value['#item']['href'], 'admin/structure/block/manage/') !== false ) {
+                    $bmifound = true;
+                }
+            }
+            if ($bmifound) {
+                $frontendtheme = variable_get('theme_default', 'none');
+                if ( $frontendtheme != 'none' ) {
+                    
+                    drupal_set_message( format_plural( $bmifound,
+                                                      'Your menu includes a block. To assure that the block displays correctly on your site, please check with the <a href="@url">menu block injector test</a>.',
+                                                      'Your menu includes @count blocks. To assure that the block displays correctly on your site, please check with the <a href="@url">menu block injector test</a>.',
+                                                      array('@url' => url('/admin/structure/menu/menutester/' . $frontendtheme) ) ) );
+                }
+            }
+        }
+        elseif (($form_id == 'menu_edit_item') && isset($form['link_path'])) {
+            if (isset($form['link_path']['#description'])) {
+                $form['link_path']['#description'] .= t(' Enter %block to have a block displayed.  Don\'t forget to choose which block to display.', array('%block' => '<block>'));
+            }
+            
+            if (isset($form['options']['#value']['unaltered_hidden'])) {
+                $form['enabled']['#default_value'] = !$form['options']['#value']['unaltered_hidden'];
+            }
+        }
+    }
+    
+    /**
+     * Implements hook_theme_registry_alter().
+     */
+    function menu_inject_block_theme_registry_alter(&$theme_registry) {
+        global $theme;
+        $frontendtheme = variable_get('theme_default', $theme);
+        if ( !function_exists($frontendtheme . '_menu_link') ) {
+            $themes = list_themes();
+            if ( isset($themes[$frontendtheme]->base_theme ) ) {
+                $menu_link_function_exists = false;
+                foreach( $themes[$frontendtheme]->base_themes as $theme_machine => $theme_human ) {
+                    if ( function_exists( $theme_machine . '_menu_link' ) ) {
+                        $menu_link_function_exists = true;
+                    }
+                }
+                if ( !$menu_link_function_exists ) {
+                    $theme_registry['menu_link']['function'] = 'menu_inject_block_theme_menu_link';
+                }
+            }
+        }
+    }
+    
+    /**
+     * Returns HTML for a menu link and submenu.
+     *
+     * @param array $variables
+     *   An associative array containing:
+     *   - element: Structured array data for a menu link.
+     *
+     * @return string
+     *   The constructed HTML.
+     *
+     * @see theme_menu_link()
+     *
+     * @ingroup theme_functions
+     */
+    function menu_inject_block_theme_menu_link($variables) {
+        $element = $variables['element'];
+        $sub_menu = '';
+        
+        if (isset($element['#original_link'])) {
+            $element['#attributes']['class'][] = 'menu-' . $element['#original_link']['mlid'];
+        }
+        
+        if ($element['#below']) {
+            $sub_menu = drupal_render($element['#below']);
+        }
+        
+        //the if-else sequence that should be reflected in YOURTHEME_menu_link function inside the template.php file of your theme
+        if (isset($element['#original_link']) && isset($element['#localized_options']) && isset($element['#localized_options']['#block_to_render']) && drupal_match_path($element['#original_link']['link_path'], "<block>\n<block>/*")) {
+            $module = $element['#localized_options']['#block_to_render']['module'];
+            $delta = $element['#localized_options']['#block_to_render']['delta'];
+            $block = block_load($module, $delta);
+            $render_array = _block_get_renderable_array(_block_render_blocks(array($block)));
+            //use a as place-holder (html5) without any attributes to maintain html structure similarity with standard entries
+            $output = '<a>' . render($render_array) . '</a>';	  			
+        }
+        else {
+            //a line like this should exist and you have to maintain the original line if it's different from the one bellow!
+            $output = l($element['#title'], $element['#href'], $element['#localized_options']) . $sub_menu;
+        }
+        //end of the if-else sequence
+        
+        return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . '</li>\n';
+        
+    }
+    
+    
+    
+    /**
+     * Implements hook_form_FORM_ID_alter().
+     */
+    function menu_inject_block_form_menu_edit_item_alter(&$form, $form_state) {
+        if (isset($form['options']['#value']['#block'])) {
+            $oldblock = $form['options']['#value']['#block'];
+        }
+        else {
+            $oldblock = '';
+        }
+        
+        $blocks = array('' => t('None'));
+        
+        foreach (module_implements('block_info') as $module) {
+            $module_blocks = module_invoke($module, 'block_info');
+            if (!empty($module_blocks)) {
+                foreach ($module_blocks as $delta => $block) {
+                    $moduledelta = $module . '-' . $delta;
+                    $blocks[$moduledelta] = $block['info'];
+                }
+            }
+        }
+        $form['block'] = array(
+                               '#title' => t('Block to inject'),
+                               '#type' => 'select',
+                               '#options' => $blocks,
+                               '#default_value' => $oldblock,
+                               );
+    }
+    
+    /**
+     * Implements hook_help().
+     */
+    function menu_inject_block_help($path, $arg) {
+        switch ($path) {
+            case 'admin/help#menu_inject_block':
+                
+                $filepath = dirname(__FILE__) . '/README.md';
+                if (file_exists($filepath)) {
+                    $readme = file_get_contents($filepath);
+                }
+                else {
+                    $filepath = dirname(__FILE__) . '/README.txt';
+                    if (file_exists($filepath)) {
+                        $readme = file_get_contents($filepath);
+                    }
+                }
+                if (!isset($readme)) {
+                    return NULL;
+                }
+                if (module_exists('markdown')) {
+                    $filters = module_invoke('markdown', 'filter_info');
+                    $info = $filters['filter_markdown'];
+                    
+                    if (function_exists($info['process callback'])) {
+                        $output = $info['process callback']($readme, NULL);
+                    }
+                    else {
+                        $output = '<pre>' . $readme . '</pre>';
+                    }
+                }
+                else {
+                    $output = '<pre>' . $readme . '</pre>';
+                }
+                
+                return $output;
+        }
     }
-  }
-
-  $form['block'] = array(
-    '#title' => t('Block to inject'),
-    '#type' => 'select',
-    '#options' => $blocks,
-    '#default_value' => $oldblock,
-  );
-}
