Calculate length directly instead of using the string