fix some logic in nesting