working version for a text file