Checking size of array before retrieving value from it