some refactoring to lib/Db.js