move core data code to its own class