Fix document options extraction and add test coverage for it