rearranged loops