add support for both window and document