changed transaction to not be in global scope, hopefully fixing duplicate bug