nit: I'd use `Node` instead of `document`