improve performance of selector code