- fixing document merging

- moving merging logic into document class
- added test
@bryevdv @mattpap please review