Refactored the code to be more readable
Wrapped in transaction. Rollback works.