Moved placement of declarations of document variables.