Fixed infinite loop in select