add bound checking for range