improve document/element/context handling.