refactored index method