further refactor/combine file-fetching logic