fix various memory leaks