Fixed bugs in memorycontext