Working nesting algorithm.
Remove Underscore dependency.
Don’t leak globals.