The loop is elevating if a string is nil, and it needs to be changed to check if a array is nil Reference https://stackoverflow.com/questions/6245929/check-for-array-not-empty-any