Added error handling for empty array of numbers