improving selection helper function