not closing connection premature when ending a transation