Fixed memory bugs.