Renamed global context variable
Refactor open/close scope functions into context
Refactor generate_type function into type_of context method