Use "setDocument" method instead of nulling document variable