Added the logic to handle when array is null.