condensed the Core Data management code in AppDelegate