Changed looping so all codes are in the same table