refactoring all data functions into one function