Everything after this point can be done before the loop, and just appended inside the loop, right?