Fix the logic in frequency selection