mainly changes to stop the segmentation faults during CopyImageMem