refactored pdf creation