speed improvement of selection function