fix debugs, change foreach($files to use $filename

Old code used $item instead of $filename, so it was less clear as to
what the code was doing.