Numerous bugfixes related to data and pic deletion