Memory clean up to fix hard to trace bugs