now works for any number of files