Refactor db.js