Further reordered loop for speed