Refactor to clean up Core Data implementation