Updated all error handling code and started moving database operations to db.js