Partial refactor to get pdf working in docs.