added conditional unwrap before deletion