refactored document creation... this is getting complicated