refactor out some of the data handling