Fixing index out of bounds error.