Fix EPERM on win32.
Code cleanup, and fix sync dir removal
v2.2.1