filling in more the the overall @extend algorithm