Refine file reading logic.