Clean application of master_sync patch

Ok this should be easier to review