updated to work with nesting and added examples