incorporating some of @dragos suggestions

avoid name duplication in contextType
remove side-effecting
try and use scope
remove closure