I am wondering whether this is a problem that would be nicely dealt with a recursive function, but I must say I am wary of recursion generally. I know it looks like sexy programming, and often very concise (if not that easy to read), but my understanding is that memory usage can get out of control easily Blobbby