fix a bug from empty array