The 5th line down in the example... treats the whole thing as UDF

Thanks but yes could be cleaned up a little bit more to make it easier to read and use.