Fixes bugs related to multiple-level nesting