fixing index out of range