minor cleanup and lock improvements. Now supports ping (which jabber servers seem to want).