Moved all database interraction into the modelapi.js file.