fixed problem with bounds checking