fix most memory leaks