Code review follow-up: validate empty input paths and boundary handling.
Code review follow-up: validate empty input paths and boundary handling.