Refactor indexCol and indexRow