fixed findIndex function