Fix error in bound checking