This function probably needs a transaction because it's a 2-query process.