minor tweaks, moved setup out of loop