Db fixes

Support both direct DB connections and connections via fh.db

Make files more modular.