big refactor of data layer