refactored file reading