Extract selector stack stuff into a separate class
Handle backrefs in selectors