fix bounds checking