Added error handling and input file parameter