We need to erase the sector before copying the data. I also fixed an endianness problem in initialize_memory_locations(). This one was not caused by me.