Working version of script: loops over all files.