modified code to handle multiple input files