selected[i] bug fixed