Under what circumstances is the residence permit extended?