refactored to work with txt