rearranged some things for loop