better handling of not having a document in layout