static int
 autogroup_add_entry( Operation *op, SlapReply *rs)
 {
-               slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
-       autogroup_info_t                *agi = (autogroup_info_t *)on->on_bi.bi_private;
+       slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
+       autogroup_info_t        *agi = (autogroup_info_t *)on->on_bi.bi_private;
        autogroup_def_t         *agd = agi->agi_def;
-       autogroup_entry_t       *age = agi->agi_entry;
+       autogroup_entry_t       *age;
        autogroup_filter_t      *agf;
        int                     rc = 0;
 
                }
        }
 
-       for ( ; age ; age = age->age_next ) {
+       
+       for ( age = agi->agi_entry; age ; age = age->age_next ) {
                ldap_pvt_thread_mutex_lock( &age->age_mutex );          
 
                /* Check if any of the filters are the suffix to the entry DN. 
 autogroup_delete_entry( Operation *op, SlapReply *rs)
 {
        slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
-       autogroup_info_t                *agi = (autogroup_info_t *)on->on_bi.bi_private;
-       autogroup_entry_t       *age = agi->agi_entry,
-                               *age_prev, *age_next;
+       autogroup_info_t        *agi = (autogroup_info_t *)on->on_bi.bi_private;
+       autogroup_entry_t       *age, *age_prev, *age_next;
        autogroup_filter_t      *agf;
        Entry                   *e;
        int                     matched_group = 0, rc = 0;
        }
 
        /* Check if the entry to be deleted is one of our groups. */
-       for ( age_next = age ; age_next ; age_prev = age, age = age_next ) {
+       for ( age_next = agi->agi_entry ; age_next ; age_prev = age ) {
+               age = age_next;
                ldap_pvt_thread_mutex_lock( &age->age_mutex );
                age_next = age->age_next;
 
 autogroup_response( Operation *op, SlapReply *rs )
 {
        slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
-       autogroup_info_t                *agi = (autogroup_info_t *)on->on_bi.bi_private;
+       autogroup_info_t        *agi = (autogroup_info_t *)on->on_bi.bi_private;
        autogroup_def_t         *agd = agi->agi_def;
-       autogroup_entry_t       *age = agi->agi_entry;
+       autogroup_entry_t       *age;
        autogroup_filter_t      *agf;
        BerValue                new_dn, new_ndn, pdn;
        Entry                   *e, *group;
 
                        ldap_pvt_thread_mutex_unlock( &agi->agi_mutex );
                }
-       }
-       if ( op->o_tag == LDAP_REQ_MODRDN ) {
+       } else if ( op->o_tag == LDAP_REQ_MODRDN ) {
                if ( rs->sr_type == REP_RESULT && rs->sr_err == LDAP_SUCCESS && !get_manageDSAit( op )) {
 
                        Debug( LDAP_DEBUG_TRACE, "==> autogroup_response MODRDN from <%s>\n", op->o_req_dn.bv_val, 0, 0);
        slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
        autogroup_info_t                *agi = (autogroup_info_t *)on->on_bi.bi_private;
        autogroup_def_t         *agd = agi->agi_def;
-       autogroup_entry_t       *age = agi->agi_entry;
+       autogroup_entry_t       *age;
        Entry                   *e;
        Attribute               *a;
 
        }
 
        /* Must refresh groups if a matching member value is modified OR filter contains memberOf=DN */
-       for ( ; age ; age = age->age_next ) {
+       for ( age = agi->agi_entry; age ; age = age->age_next ) {
                autogroup_filter_t      *agf;
                for ( agf = age->age_filter ; agf ; agf = agf->agf_next ) {
                        if ( agf->agf_anlist ) {
 autogroup_modrdn_entry( Operation *op, SlapReply *rs)
 {
        slap_overinst           *on = (slap_overinst *)op->o_bd->bd_info;
-       autogroup_info_t                *agi = (autogroup_info_t *)on->on_bi.bi_private;
-       autogroup_entry_t       *age = agi->agi_entry;
+       autogroup_info_t        *agi = (autogroup_info_t *)on->on_bi.bi_private;
+       autogroup_entry_t       *age;
        Entry                   *e;
 
        if ( get_manageDSAit( op ) ) {
        }
 
        /* Must check if a dn is modified */
-       for ( ; age ; age = age->age_next ) {
+       for ( age = agi->agi_entry; age ; age = age->age_next ) {
                autogroup_filter_t      *agf;
                for ( agf = age->age_filter ; agf ; agf = agf->agf_next ) {
                        if ( agf->agf_anlist ) {