finish the rewriting of selector engine