Added code to flatten files automatically.