added some error checking back for directories and non text files