Reading files from a function