refactoring to use ldap function