improved error handling for empty input arrays (take 2)