working with text file; need output and refactoring