Added error handling and parameter for input file