Renamed some variables and pulled out DB logic into api.js