fix the out of bounds errors sometime