Moved setting of managed object context as the first thing.