fixed the select loop bug