some code cleanup but memory still leaks