Nested loops seem to work faster