outer loop