Handle nested empty array case by checking length

Just a quick bounds check before entering an empty array (currently it assumes at least one element). :)