Fixed some memory bugs.