Put DB saving in its own function.