pull connection out of the loop, oops
update code