removed dependency on window.document