moved a loop stuff in front