updated assembly to ensure we do not write into improper memory