command line arguments and file opening logic updated