Revised nesting functionality.

This will require some serious testing