read files into memory once to reduce fopen overhead