fixed serious memory leaks.