Use 'defer' to rollback transactions