Extract function to load text from file