Refactor to split out the data layer