database.js refactoring