refactored document post-loading code to its own method