Fixed bugs of memory management