I think this code would be way simpler if you just had 2 separate branches, one for `nil` and the other for "array result".