make program run in a loop, move definition up