refactor findInRow, findInBox and findInCol functions