fixed major memory leaks