fix select logic