improved nesting and formatting