I've rewritten it to avoid the three database writes, but kept the behaviour explicit :)