abstract data loading to a function