Tidied up code in db.js