thread-local connections and other bugfixes