Refactoring the showIndex code a bit