Avoiding errors due to an empty array