new version without recreating the connection at every iteration