working code w/ logic to check before and after transaction