Extract Core Data task into a block variable

To be able to call the same task from the background and the main thread.