Fixed handling of empty array
Fixed #1: exception handling