Combined some for loops into one.