pull code out of loop