Apply code review fixes: validation, error handling, and cleanup
All checks were successful
CI / test (pull_request) Successful in 43s