show and index page code refactored