refactor database.js