Added a fix for dealing correctly with deep nesting and generic contexts