I should add: the problem could be in the ptr_remove too, because it removes the new panel created instead of the old.