Fixes the segmentation fault and various related bugs through editing, changeimagelayerproperties.cpp and addReference and removeReference instead.