reduce memory footprint for removeWithKey