Fixing index out of bounds.