reorganize: move data fetching to function