improved script to read two input files