added outer loop to processing output records