update context-related logic
get rid of DOCUMENT and HTML constants