have an option to specify output file, restructure the code to find input files