Implemented separate sub-routine to consider the three possible file extensions. (plain, .gz, or .Z)