more fixes to minimize heap thrashing