Wrote a transaction function, but I'm not sure if it's really 100% successful in how it works. Probably needs some investigation.