memory performance upgrades stolen from @jleahey