File reading logic