Fix for doc being assumed to be window.document