Fixed index out of bounds and current recurring issue