Some fixes towards not losing as much memory.