Fix bug allowing created elements to reference deleted ones