Fix incorrect detach of images