Fixed possible empty array bug