"As Yahweh commanded"
Here the word "he" refers to each man whom Moses counted.
Here the words "they" and "them" refer to Moses and Aaron.