Interchanged some loops so the data is easier to parse