Proper handling of documents and their frames.

Signed-off-by: Kristian Duske <kristian.duske@gmail.com>