Some code refactoring and bug fix for empty array

I refactored the code mostly for clarity.  The circular dependency check is less of a hack/exception case than it is a byproduct of the recursion now.

In addition, I added the check for when there's an empty array being passed as a license