diff --git a/ldap_servers/LdapServer.class.php b/ldap_servers/LdapServer.class.php
index 09979c2..4db2916 100644
--- a/ldap_servers/LdapServer.class.php
+++ b/ldap_servers/LdapServer.class.php
@@ -285,12 +285,12 @@ class LdapServer {
 
 
   /**
-	 * Bind (authenticate) against an active LDAP database.
-	 *
-	 * @param $userdn
-	 *   The DN to bind against. If NULL, we use $this->binddn
-	 * @param $pass
-	 *   The password search base. If NULL, we use $this->bindpw
+   * Bind (authenticate) against an active LDAP database.
+   *
+   * @param $userdn
+   *   The DN to bind against. If NULL, we use $this->binddn
+   * @param $pass
+   *   The password search base. If NULL, we use $this->bindpw
    *
    * @return
    *   Result of bind; TRUE if successful, FALSE otherwise.
@@ -1021,28 +1021,28 @@ class LdapServer {
     }
   }
 
-	/**
-	 * @param ldap entry array $ldap_entry
-	 *
-	 * @return drupal file object image user's thumbnail or FALSE if none present or ERROR happens.
-	 */
-	public function userPictureFromLdapEntry($ldap_entry, $drupal_username = FALSE) {
-		if ($ldap_entry && $this->picture_attr) {
-			//Check if ldap entry has been provisioned.
-
-			$thumb = isset($ldap_entry[$this->picture_attr][0]) ? $ldap_entry[$this->picture_attr][0] : FALSE;
-			if(!$thumb){
-				return FALSE;
-			}
-
-			//Create md5 check.
-			$md5thumb = md5($thumb);
-
-			/**
-			 * If existing account already has picture check if it has changed if so remove old file and create the new one
-		   * If picture is not set but account has md5 something is wrong exit.
-			 */
-			if ($drupal_username && $account = user_load_by_name($drupal_username)) {
+  /**
+   * @param ldap entry array $ldap_entry
+   *
+   * @return drupal file object image user's thumbnail or FALSE if none present or ERROR happens.
+   */
+  public function userPictureFromLdapEntry($ldap_entry, $drupal_username = FALSE) {
+    if ($ldap_entry && $this->picture_attr) {
+      //Check if ldap entry has been provisioned.
+
+      $thumb = isset($ldap_entry[$this->picture_attr][0]) ? $ldap_entry[$this->picture_attr][0] : FALSE;
+      if(!$thumb){
+        return FALSE;
+      }
+
+      //Create md5 check.
+      $md5thumb = md5($thumb);
+
+      /**
+       * If existing account already has picture check if it has changed if so remove old file and create the new one
+       * If picture is not set but account has md5 something is wrong exit.
+       */
+      if ($drupal_username && $account = user_load_by_name($drupal_username)) {
         if ($account->uid == 0 || $account->uid == 1){
           return FALSE;
         }
@@ -1068,33 +1068,33 @@ class LdapServer {
           return FALSE;
         }
       }
-			//Create tmp file to get image format.
-			$filename = uniqid();
-			$fileuri = file_directory_temp() .'/'. $filename;
-			$size = file_put_contents($fileuri, $thumb);
-			$info = image_get_info($fileuri);
-			unlink($fileuri);
-			// create file object
-			$file = file_save_data($thumb, 'public://' . variable_get('user_picture_path') .'/'. $filename .'.'. $info['extension']);
-			$file->md5Sum = $md5thumb;
-			// standard Drupal validators for user pictures
-			$validators = array(
-					'file_validate_is_image' => array(),
-					'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
-					'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
-			);
-			$errors = file_validate($file ,$validators);
-			if (empty($errors)) {
-				return $file;
-			}
+      //Create tmp file to get image format.
+      $filename = uniqid();
+      $fileuri = file_directory_temp() .'/'. $filename;
+      $size = file_put_contents($fileuri, $thumb);
+      $info = image_get_info($fileuri);
+      unlink($fileuri);
+      // create file object
+      $file = file_save_data($thumb, 'public://' . variable_get('user_picture_path') .'/'. $filename .'.'. $info['extension']);
+      $file->md5Sum = $md5thumb;
+      // standard Drupal validators for user pictures
+      $validators = array(
+          'file_validate_is_image' => array(),
+          'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
+          'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
+      );
+      $errors = file_validate($file ,$validators);
+      if (empty($errors)) {
+        return $file;
+      }
       else {
-				foreach ($errors as $err => $err_val){
-					watchdog('ldap_server', "Error storing picture: %$err", "%$err_val", WATCHDOG_ERROR );
-				}
-				return FALSE;
-			}
-		}
-	}
+        foreach ($errors as $err => $err_val){
+          watchdog('ldap_server', "Error storing picture: %$err", "%$err_val", WATCHDOG_ERROR );
+        }
+        return FALSE;
+      }
+    }
+  }
 
 
   /**
@@ -1686,8 +1686,14 @@ class LdapServer {
     foreach ($this->basedn as $base_dn) {  // need to search on all basedns one at a time
       $group_entries = $this->search($base_dn, $group_query, array()); // only need dn, so empty array forces return of no attributes
       if ($group_entries !== FALSE) {
-        $max_levels = ($nested) ? LDAP_SERVER_LDAP_QUERY_RECURSION_LIMIT : 0;
-        $this->groupMembershipsFromEntryRecursive($group_entries, $all_group_dns, $tested_group_ids, $level, $max_levels);
+        if($nested) {
+          $max_levels = ($nested) ? LDAP_SERVER_LDAP_QUERY_RECURSION_LIMIT : 0;
+          $this->groupMembershipsFromEntryResursive($group_entries, $all_group_dns, $tested_group_ids, $level, $max_levels);
+        } else {
+                 foreach($group_entries as $group_entry) {
+                   $all_group_dns[]=$group_entry['dn'];
+                 }
+        }
       }
     }
 
@@ -1869,4 +1875,4 @@ class LdapServersRebindHandler {
     }
     return 0;
   }
-}
\ No newline at end of file
+}
