refactor reading of files into new readFile() function