move print out of loop