cleanups and optimizations

- only normalize option attributes for top-level document
- only set dynamic attributes on top-level document
- set dynamic attributes before loading reader
- optimize several non-nil checks