copy some stuff over from MemoryTamer