diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp
index dbf7a4a..fd7f8f9 100644
--- a/modules/extra/m_ldap.cpp
+++ b/modules/extra/m_ldap.cpp
@@ -64,8 +64,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 		if (last_connect > Anope::CurTime - 60)
 			throw LDAPException("Unable to connect to LDAP service " + this->name + ": reconnecting too fast");
 		last_connect = Anope::CurTime;
-
 		ldap_unbind_ext(this->con, NULL, NULL);
+Log(LOG_DEBUG) << "*** ldap_unbind_ext(id = " << this->con << ", NULL, NULL);";
 		int i = ldap_initialize(&this->con, this->server.c_str());
 		if (i != LDAP_SUCCESS)
 			throw LDAPException("Unable to connect to LDAP service " + this->name + ": " + ldap_err2string(i));
@@ -80,16 +80,22 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 	LDAPService(Module *o, const Anope::string &n, const Anope::string &s, int po, const Anope::string &b, const Anope::string &p, time_t t) : LDAPProvider(o, n), server(s), port(po), admin_binddn(b), admin_pass(p), timeout(t), last_connect(0)
 	{
 		int i = ldap_initialize(&this->con, this->server.c_str());
+Log(LOG_DEBUG) << "*** ldap_initialize(this->con, " << this->server.c_str() << ");";
+
 		if (i != LDAP_SUCCESS)
 			throw LDAPException("Unable to connect to LDAP service " + this->name + ": " + ldap_err2string(i));
 
 		const int version = LDAP_VERSION3;
 		i = ldap_set_option(this->con, LDAP_OPT_PROTOCOL_VERSION, &version);
+Log(LOG_DEBUG) << "*** ldap_set_option(this->con, LDAP_OPT_PROTOCOL_VERSION, LDAP_VERSION3);";
+
 		if (i != LDAP_OPT_SUCCESS)
 			throw LDAPException("Unable to set protocol version for " + this->name + ": " + ldap_err2string(i));
 
 		const struct timeval tv = { 0, 0 };
 		i = ldap_set_option(this->con, LDAP_OPT_NETWORK_TIMEOUT, &tv);
+Log(LOG_DEBUG) << "*** ldap_set_option(this->con, LDAP_OPT_NETWORK_TIMEOUT, &tv);";
+
 		if (i != LDAP_OPT_SUCCESS)
 			throw LDAPException("Unable to set timeout for " + this->name + ": " + ldap_err2string(i));
 	}
@@ -102,8 +108,9 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 		{
 			LDAPQuery msgid = it->first;
 			LDAPInterface *i = it->second.second;
-
 			ldap_abandon_ext(this->con, msgid, NULL, NULL);
+Log(LOG_DEBUG) << "*** " << msgid << " ldap_abandon_ext(this->con, \"" << msgid << "\", NULL, NULL);";
+
 			if (i)
 				i->OnDelete();
 		}
@@ -123,12 +130,14 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 		this->results.clear();
 
 		this->Unlock();
-
 		ldap_unbind_ext(this->con, NULL, NULL);
+Log(LOG_DEBUG) << "*** ldap_unbind_ext(this->con, NULL, NULL);";
+
 	}
 	
 	LDAPQuery BindAsAdmin(LDAPInterface *i)
 	{
+Log(LOG_DEBUG) << "*** BindAsAdmin();";
 		return this->Bind(i, this->admin_binddn, this->admin_pass);
 	}
 
@@ -140,6 +149,7 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 
 		LDAPQuery msgid;
 		int ret = ldap_sasl_bind(con, who.c_str(), LDAP_SASL_SIMPLE, &cred, NULL, NULL, &msgid);
+Log(LOG_DEBUG) << "*** " << msgid << " ldap_sasl_bind(con, \"" << who << "\", LDAP_SASL_SIMPLE, \"PASSWORD\", NULL, NULL, " << msgid << ");";
 		free(cred.bv_val);
 		if (ret != LDAP_SUCCESS)
 		{
@@ -170,6 +180,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 
 		LDAPQuery msgid;
 		int ret = ldap_search_ext(this->con, base.c_str(), LDAP_SCOPE_SUBTREE, filter.c_str(), NULL, 0, NULL, NULL, NULL, 0, &msgid);
+Log(LOG_DEBUG) << "*** " << msgid << " ldap_search_ext(this->con, \"" << base << "\", LDAP_SCOPE_SUBTREE, \"" << filter << "\", NULL, 0, NULL, NULL, NULL, 0, " << msgid << ");";
+
 		if (ret != LDAP_SUCCESS)
 		{
 			if (ret == LDAP_SERVER_DOWN || ret == LDAP_TIMEOUT)
@@ -194,6 +206,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 		LDAPMod **mods = this->BuildMods(attributes);
 		LDAPQuery msgid;
 		int ret = ldap_add_ext(this->con, dn.c_str(), mods, NULL, NULL, &msgid);
+Log(LOG_DEBUG) << "*** " << msgid << "ldap_add_ext(this->con, " << dn << ", " << mods << ", NULL, NULL, " << msgid << ");";
+
 		this->FreeMods(mods);
 
 		if (ret != LDAP_SUCCESS)
@@ -222,6 +236,7 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 	{
 		LDAPQuery msgid;
 		int ret = ldap_delete_ext(this->con, dn.c_str(), NULL, NULL, &msgid);
+Log(LOG_DEBUG) << "*** " << msgid << "ldap_delete_ext(this->con, " << dn << ", NULL, NULL, " << msgid << ");";
 
 		if (ret != LDAP_SUCCESS)
 		{
@@ -250,6 +265,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 		LDAPMod **mods = this->BuildMods(attributes);
 		LDAPQuery msgid;
 		int ret = ldap_modify_ext(this->con, base.c_str(), mods, NULL, NULL, &msgid);
+Log(LOG_DEBUG) << "*** " << msgid << "ldap_modify_ext(this->con, " << base << ", " << mods << ", NULL, NULL, " << msgid << ");";
+
 		this->FreeMods(mods);
 
 		if (ret != LDAP_SUCCESS)
@@ -289,7 +306,7 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 			{
 				LDAPResult *ldap_result = new LDAPResult();
 				ldap_result->id = msgid;
-				ldap_result->error = "Query timed out";
+				ldap_result->error = Anope::printf("Query timed out (msgid=%i)", msgid);
 
 				this->queries.erase(msgid);
 				this->results.push_back(std::make_pair(i, ldap_result));
@@ -315,14 +332,17 @@ class LDAPService : public LDAPProvider, public Thread, public Condition
 			else
 				this->Timeout();
 
+Log(LOG_DEBUG) << "*** this->queries.size() = " << this->queries.size();
 			struct timeval tv = { 1, 0 };
 			LDAPMessage *result;
 			int rtype = ldap_result(this->con, LDAP_RES_ANY, 1, &tv, &result);
+Log(LOG_DEBUG) << "*** ldap_result(this->con, LDAP_RES_ANY, 1, &tv, &result);";
+
 			if (rtype <= 0)
 				continue;
 
 			int cur_id = ldap_msgid(result);
-
+Log(LOG_DEBUG) << "msgid = " << cur_id << ", rtype = " << rtype;
 			this->Lock();
 
 			query_queue::iterator it = this->queries.find(cur_id);
