optimize selection function