Refactor reloadToIndex function