Fix error: "Undefined variable document"