Refactored for any input text file