fixed potential memory leaks