refactored database.js more