Move code to run outside loop.