improved error handling for empty input arrays