Re-arrange loop