cleanup - avoid reconnecting every iteration of loop and removed unnecessary final block