extracted the file loading logic