Fix handling of nested contexts and recursive set