Fix out of bounds problem