Simplified changes made in previous commits to make sure that the LDAP connections are closed properly.