Added check for existence of items in last array