Fix issue with memory overwrite