added comments and modified the transaction logic when persisting events.