Fixed bugs when testing with real db and ldap. Works now.