Sync fixes

The below are based on reading and writing the code, no strong testing for all of these conditions was done to show a real problem or that the fix necessarily works so review critically.