code reorganization (changed file loop position