largestWidth function simplified