switching to safe mongo connections and some other bugfixes