fixed potential memory leaks.