fixed bugs based on document and window object