how to make this transaction atomic?