This ``$extend`` looks a little mysterious. It would be good to add a comment explaining why we need to do this.