Move string length calculation to separate method