Properly insert the doctype of the document into the iframe/destination doc

This is a huge fix. But do not merge until tests are written!