Although reading this code -- I think @document does need to get cleared when switching windows