branch histories should now be added to merged document's history. cleaned up code a bit