Fixed all memory bugs