Do code refinement, move the core data code to main thread