CoreData stuff implementation. Refactoring.