Index: account_profile.module
===================================================================
--- account_profile.module	(revision 19388)
+++ account_profile.module	(working copy)
@@ -37,10 +37,18 @@
  * Implementation of hook_form_alter().
  */
 function account_profile_form_alter(&$form, $form_state, $form_id) {
-  $profile = variable_get('account_profile_main_profile', key(content_profile_get_types('names'))); // get main profile name
+  $edit_user = user_load($form['#uid']);
+  unset($edit_user->roles[2]);
+  $main_profile = variable_get('account_profile_main_profile', key(content_profile_get_types('names'))); // get main profile name
+  if(array_search($main_profile, $edit_user->roles)){
+    $profile = $main_profile;
+  }
+  else{
+    $profile = array_shift($edit_user->roles);
+  }
   switch ($form_id) {
     case 'user_profile_form':
-        if (variable_get('account_profile_redirect', TRUE)) {
+        if (variable_get('account_profile_redirect', TRUE) && isset($profile)) {
           if (isset($_REQUEST['destination'])) {
             $destination = $_REQUEST['destination'];
             unset($_REQUEST['destination']);
