improved ldap code