Fixed some memory management issues.