better handling of document elements