pull loop into internal lib