Added check for globalDocument