proper loop order