fixes type checking errors-iterating over indices