Reversed order of vectors, refactored into for loop with while loops inside