updated the logic to make selections more intelligent